Issue 173583
Summary clang-format: Compound literal in macro is treated as function and wrapped
Labels clang-format
Assignees
Reporter hueychen27
    Given the following C code which takes the address of an _expression_ using a compound literal:
```c
#define getAddr(v, type) &(type){v}
```

And the `.clang-format` config file:
```yaml
IndentWidth: 4
TabWidth: 4
UseTab: Never
---
Language: Cpp

AlignEscapedNewlines: LeftWithLastLine
AllowShortFunctionsOnASingleLine: Empty

BreakBeforeBraces: Attach
```
It becomes:
```c
#define getAddr(v, type) \
    &(type) {            \
        v \
    }
```

It should be kept the same (not formatted like the above) as it is a compound literal.

Weirdly, `clang-format` treats `&` as a function identifier and formats it like a function.

Evidence is shown with:
```c
#define getAddr(v, type) int &(type){v;}
```
Being formatted as:
```c
#define getAddr(v, type) \
    int &(type) {        \
 v;               \
    }
```

Changing `AllowShortFunctionsOnASingleLine` to `All` yields:
```c
#define getAddr(v, type) \
    &(type) { v }
```
Which is abnormal since there shouldn't be a break.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to