[PATCH] D123737: [clang-format] Skip preprocessor lines when finding the record lbrace

Arthur Eubanks via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 14 09:31:36 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf14ebe91c5dd: [clang-format] Skip preprocessor lines when finding the record lbrace (authored by aeubanks).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123737

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12766,6 +12766,13 @@
                "};",
                MergeInlineOnly);
 
+  verifyFormat("class C {\n"
+               "#ifdef A\n"
+               "  int f() { return 42; }\n"
+               "#endif\n"
+               "};",
+               MergeInlineOnly);
+
   // Also verify behavior when BraceWrapping.AfterFunction = true
   MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom;
   MergeInlineOnly.BraceWrapping.AfterFunction = true;
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -308,7 +308,7 @@
           // Find the last line with lower level.
           auto J = I - 1;
           for (; J != AnnotatedLines.begin(); --J)
-            if ((*J)->Level < TheLine->Level)
+            if (!(*J)->InPPDirective && (*J)->Level < TheLine->Level)
               break;
           if ((*J)->Level >= TheLine->Level)
             return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123737.422893.patch
Type: text/x-patch
Size: 1232 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220414/20787426/attachment.bin>


More information about the cfe-commits mailing list