Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-format - incorrect formating of macros #170

Closed
DmitrySokolov opened this issue Mar 12, 2020 · 1 comment
Closed

clang-format - incorrect formating of macros #170

DmitrySokolov opened this issue Mar 12, 2020 · 1 comment

Comments

@DmitrySokolov
Copy link

clang-format version 11.0.0 (https://github.com/llvm/llvm-project.git 7420f96)

---
Language:        Cpp
# BasedOnStyle:  Google
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: true
AlignEscapedNewlines: Left
AlignOperands:   true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BreakBeforeBraces: Custom
BraceWrapping:
  AfterCaseLabel:  false
  AfterClass:      true
  AfterControlStatement: false
  AfterEnum:       true
  AfterFunction:   true
  AfterNamespace:  false
  AfterObjCDeclaration: false
  AfterStruct:     true
  AfterUnion:      true
  AfterExternBlock: false
  BeforeCatch:     true
  BeforeElse:      true
  BeforeLambdaBody: false
  IndentBraces:    false
  SplitEmptyFunction: false
  SplitEmptyRecord: false
  SplitEmptyNamespace: true
BreakAfterJavaFieldAnnotations: false
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakBeforeInheritanceComma: true
BreakInheritanceList: BeforeComma
BreakConstructorInitializersBeforeComma: true
BreakConstructorInitializers: BeforeComma
BreakStringLiterals: true
ColumnLimit:     100
CommentPragmas:  '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 8
ContinuationIndentWidth: 8
Cpp11BracedListStyle: true
DeriveLineEnding: false
DerivePointerAlignment: false
DisableFormat:   false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
  - foreach
  - Q_FOREACH
  - BOOST_FOREACH
IncludeBlocks:   Preserve
IncludeCategories:
  - Regex:           '^<ext/.*\.h>'
    Priority:        2
  - Regex:           '^<.*\.h>'
    Priority:        1
  - Regex:           '^<.*'
    Priority:        2
  - Regex:           '.*'
    Priority:        3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseBlocks: false
IndentCaseLabels: true
IndentGotoLabels: true
IndentPPDirectives: AfterHash
IndentWidth:     4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: 'MAP$|_BEGIN$|START_WRAPPER$'
MacroBlockEnd:   '_END$|END_WRAPPER$'
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
RawStringFormats:
  - Language:        Cpp
    Delimiters:
      - cc
      - CC
      - cpp
      - Cpp
      - CPP
      - 'c++'
      - 'C++'
    CanonicalDelimiter: ''
    BasedOnStyle:    google
  - Language:        TextProto
    Delimiters:
      - pb
      - PB
      - proto
      - PROTO
    EnclosingFunctions:
      - EqualsProto
      - EquivToProto
      - PARSE_PARTIAL_TEXT_PROTO
      - PARSE_TEST_PROTO
      - PARSE_TEXT_PROTO
      - ParseTextOrDie
      - ParseTextProtoOrDie
    CanonicalDelimiter: ''
    BasedOnStyle:    google
ReflowComments:  true
SortIncludes:    false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: true
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles:  false
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard:        Auto
StatementMacros:
  - Q_UNUSED
  - QT_REQUIRE_VERSION
TabWidth:        8
UseCRLF:         true
UseTab:          Never
...

test.cpp

#define FUNC_BEGIN(name, ret) \
  struct Class_##name { \
    static ret run (void *ctx) { \
        return ((Class_##name*)ctx)->operator()(); \
    } \
    inline ret operator() () {

#define FUNC_END(name) \
    } \
 \
    Class_##name()  {} \
  }; \
  Class_##name name;

test_actual.cpp

#define FUNC_BEGIN(name, ret)                                                    \
    struct Class_##name                                                          \
    {                                                                            \
        static ret run(void* ctx) { return ((Class_##name*)ctx)->operator()(); } \
        inline ret operator()() { #define FUNC_END(name) }                       \
                                                                                 \
    Class_##name() {}                                                            \
    }                                                                            \
    ;                                                                            \
    Class_##name name;

test_expected.cpp

#define FUNC_BEGIN(name, ret)                    \
  struct Class_##name {                          \
    static ret run (void *ctx) {                 \
      return ((Class_##name*)ctx)->operator()(); \
    }                                            \
    inline ret operator() () {

#define FUNC_END(name) \
    }                  \
                       \
    Class_##name()  {} \
  };                   \
  Class_##name name;
@rymiel
Copy link
Member

rymiel commented Sep 9, 2023

This issue seems to describe invalid-code-generation when it comes to macros. This was fixed by ca0d970 as part of clang-format 15

The output with a modern version is the following:

#define FUNC_BEGIN(name, ret)                          \
    struct Class_##name                                \
    {                                                  \
        static ret run(void* ctx)                      \
        {                                              \
            return ((Class_##name*)ctx)->operator()(); \
        }                                              \
        inline ret operator()()                        \
        {
#define FUNC_END(name) \
    }                  \
                       \
    Class_##name()     \
    {}                 \
    }                  \
    ;                  \
    Class_##name name;

Which doesn't match the expected output, but it at least doesn't break compilation. I don't think clang-format can do much better when it comes to incomplete code fragments, but the invalid-code-generation is fixed

@rymiel rymiel closed this as completed Sep 9, 2023
moodyhunter pushed a commit to moodyhunter/llvm-project that referenced this issue Mar 26, 2024
Update to LLVM 18.1.1 (+ additional commits)
mjklemm pushed a commit to mjklemm/llvm-project that referenced this issue Sep 30, 2024
* [flang][driver] Increase default -fopenmp-version to 52

    - Currently set to 11

* Fix lit tests & update version in Frontend/CompilerInvocation.cpp

* Fix one more test flang/test/Driver/flang-openmp-version-macro.f90
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants