[PATCH] D150057: [clang-format] Fix consecutive alignments in #else blocks

Björn Schäpers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 9 12:06:57 PDT 2023


HazardyKnusperkeks 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"
----------------
owenpan wrote:
> 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;
> ```
Fascinating. But wouldn't the better fix be that the directives are not marked as finalized?


================
Comment at: clang/unittests/Format/FormatTestComments.cpp:4319
 /\
-/ 
+/
   )",
----------------
owenpan wrote:
> 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.
Okay, but that wasn't really trailing, it was part of a string.


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