[PATCH] D150057: [clang-format] Fix consecutive alignments in #else blocks
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun May 7 14:21:09 PDT 2023
owenpan added inline comments.
================
Comment at: clang/unittests/Format/FormatTest.cpp:6371-6380
+ verifyFormat("#if FOO\n"
+ "int a = 1;\n"
+ "#else\n"
+ "int ab = 2;\n"
+ "#endif\n"
+ "#ifdef BAR\n"
+ "int abc = 3;\n"
----------------
clang-format breaks the above into two separate sets:
```
#if FOO
int a = 1;
#else
#endif
#if BAR
int abc = 3;
#else
#endif
```
and:
```
#if FOO
#else
int ab = 2;
#endif
#if BAR
#else
int abcd = 4;
#endif
```
After it finishes with the first set, the preprocessor directives are marked as `Finalized`. Then, while the second set is being processed, the directives should //not// be skipped when tokens are added to the `Change` set. Otherwise, we would end up with the `Change` set below without any "scope" context:
```
int ab = 2;
int abcd = 4;
```
================
Comment at: clang/unittests/Format/FormatTestComments.cpp:4319
/\
-/
+/
)",
----------------
HazardyKnusperkeks wrote:
> Unrelated?
My editor strips trailing whitespaces on save. I'll leave the fix in because it's not worth doing it in a separate patch.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D150057/new/
https://reviews.llvm.org/D150057
More information about the cfe-commits
mailing list