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

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 9 14:52:21 PDT 2023


owenpan marked 2 inline comments as done.
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"
----------------
HazardyKnusperkeks wrote:
> 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?
I tried that first, but it broke a lot of unit tests. I'll give it another try when I have time. :)


================
Comment at: clang/unittests/Format/FormatTestComments.cpp:4319
 /\
-/ 
+/
   )",
----------------
HazardyKnusperkeks wrote:
> 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.
Yeah. Fixed in e9acf00. Thanks!


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