[PATCH] D137052: [clang-format] Don't skip #else/#elif of #if 0

sstwcw via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 30 20:33:15 PDT 2022


sstwcw added a comment.

This patch fixes the regression caused by 2183fe2 <https://reviews.llvm.org/rG2183fe2160fbcb754893e98829f2bff4d0fccfa3> while introducing a new regression.  But in my opinion the new regression is less of a problem than the old one.  Therefore I think it is okay.

Take this piece of code similar to the example in 71814b4.

before

  void SomeFunction(int param1,
                    template <
  #ifdef A
  #if 0
  #endif
                        MyType<Some>>
  #else
                        Type1, Type2>
  #endif
                    param2,
                    param3) {
    f();
  }

after

  void SomeFunction(int param1,
                    template <
  #ifdef A
  #if 0
  #endif
                        MyType<Some>>
  #else
                    Type1,
                    Type2 >
  #endif
                        param2,
                    param3) {
    f();
  }



================
Comment at: clang/lib/Format/UnwrappedLineParser.cpp:1150
   }
-  PPChainBranchIndex.push(0);
+  if (!Unreachable)
+    PPChainBranchIndex.push(0);
----------------
Can you add a comment here saying this line is a nasty hack which breaks the assumption that `PPChainBranchIndex` should have as many entries as the number of nestings of preprocessor branches and we should probably come up with a better way?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137052/new/

https://reviews.llvm.org/D137052



More information about the cfe-commits mailing list