Issue 58214
Summary clang-format attempts to add the lines of code after macro definition to the macro
Labels new issue
Assignees
Reporter jacob-abraham
    I have a macro definition, followed by an include statement. Below is what it should look like.

```c
#define CUSTOM(name)                                                           \
    case i64_##name: return "custom_" #name;
#include "file.inc"
```

If I now run clang-format on it, the formatted code is below.

```
#define CUSTOM(name)                                                           \
    case i64_##name: return "custom_" #name; #include "file.inc"
```

This breaks the meaning of the code.

This is my .clang-format file

```
BreakBeforeBraces: Attach
AlignAfterOpenBracket: AlwaysBreak
SpaceBeforeParens: Never
IndentWidth: 4
ColumnLimit: 80
IndentCaseLabels: true
UseTab: Never
PointerAlignment: Left
IndentPPDirectives: BeforeHash
AllowShortCaseLabelsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: AllIfsAndElse

BinPackArguments: false
AllowAllParametersOfDeclarationOnNextLine: false
BinPackParameters: false
AllowAllArgumentsOnNextLine: false
```

If I removed `AllowShortCaseLabelsOnASingleLine: true`, then it properly does not add the include to the macro. If I do it with any other kind of statement after the macro, it does not add it to the macro definition. If I add any kind of statement after the macro, it works as expected.

This is a stripped-down example that is independent of my code. I have a number of patterns like this in my code and this is the only one that breaks, from what I can tell it is having the case statement inside of a macro with the include statement afterward with no statement after the include statement that causes the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to