Author: Marek Kurdej
Date: 2022-03-13T22:17:48+01:00
New Revision: 0570af17585d98be0c12f6760118eb94071d9c26

URL: 
https://github.com/llvm/llvm-project/commit/0570af17585d98be0c12f6760118eb94071d9c26
DIFF: 
https://github.com/llvm/llvm-project/commit/0570af17585d98be0c12f6760118eb94071d9c26.diff

LOG: [clang-format] Fix incorrect assertion on macro definitions with keyword 
class.

Fixes https://github.com/llvm/llvm-project/issues/54348.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 5b5439901b2f7..1393a2a321183 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -484,7 +484,8 @@ class LineJoiner {
       } else {
         // Try to merge a block with left brace unwrapped that wasn't yet
         // covered.
-        assert(!TheLine->First->isOneOf(tok::kw_class, tok::kw_enum,
+        assert(TheLine->InPPDirective ||
+               !TheLine->First->isOneOf(tok::kw_class, tok::kw_enum,
                                         tok::kw_struct));
         ShouldMerge = !Style.BraceWrapping.AfterFunction ||
                       (NextLine.First->is(tok::r_brace) &&

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 45e8c0b79cfb2..baa3993805bcb 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1877,6 +1877,13 @@ TEST_F(FormatTest, UnderstandsMacros) {
   verifyFormat("#define __except(x)");
   verifyFormat("#define __try(x)");
 
+  // https://llvm.org/PR54348.
+  verifyFormat(
+      "#define A"
+      "                                                                      "
+      "\\\n"
+      "  class & {}");
+
   FormatStyle Style = getLLVMStyle();
   Style.BreakBeforeBraces = FormatStyle::BS_Custom;
   Style.BraceWrapping.AfterFunction = true;


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to