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

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 21 15:21:08 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"
----------------
owenpan wrote:
> 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. :)
See D153243.


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