| Issue |
56685
|
| Summary |
clang-format misformats designated initializers mixed with preprocessor blocks
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
zetafunction
|
Clang-format file:
```
BasedOnStyle: Chromium
Standard: Cpp11
```
Example 1, where the #else block is surprisingly indented:
```c++
int main() {
SOME_MACRO((SomeStruct {
.some_long_field_name = 1,
#if defined(SOME_FLAG)
.to_prevent_multiple_inits_on_one_line = 2,
.is_this_indented_weirdly_2 = 3,
#else
.yet_another_long_field_name = 3,
#endif
.the_final_initializer_whee = 4,
}),
second_macro_arg);
}
```
Example 2, where a comment in the #if block causes the next line to be surprisingly indented:
```c++
int main() {
SOME_MACRO((SomeStruct {
.some_long_field_name = 1,
#if defined(SOME_FLAG)
// Some useful comment here.
.to_prevent_multiple_inits_on_one_line = 2,
#else
.yet_another_long_field_name = 3,
#endif
.the_final_initializer_whee = 4,
}),
second_macro_arg);
}
```
Example 3, where reversing the order of the comment and the designated initializer results in the comment being lined up with... something:
```c++
int main() {
SOME_MACRO((SomeStruct {
.some_long_field_name = 1,
#if defined(SOME_FLAG)
.to_prevent_multiple_inits_on_one_line = 2,
// Some useful comment here.
#else
// Another useful comment here.
.yet_another_long_field_name = 3,
#endif
.the_final_initializer_whee = 4,
}),
second_macro_arg);
}
```
Example 4, where a comment in the #else block is also indented in a surprising way:
```c++
int main() {
SOME_MACRO((SomeStruct {
.some_long_field_name = 1,
#if defined(SOME_FLAG)
// Some useful comment here.
.to_prevent_multiple_inits_on_one_line = 2,
#else
// Another useful comment here.
.yet_another_long_field_name = 3,
#endif
.the_final_initializer_whee = 4,
}),
second_macro_arg);
}
```
In all of these examples, I would have expected the designated initializers to be lined up.
In examples 2 and 4, I would have expected the comments to be lined up with the designated initializer on the next line.
In example 3, I can kind of understand the weird indent of the `//` comment, since it could be read as applying to the `#else`, though generally speaking, the alignment is still a bit wonky.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs