owenpan updated this revision to Diff 405881.
owenpan added a comment.

Added a test case.


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

https://reviews.llvm.org/D118969

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===================================================================
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -91,6 +91,12 @@
   EXPECT_TOKEN(Tokens[2], tok::l_brace, TT_RecordLBrace);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsLBracesInMacroDefinition) {
+  auto Tokens = annotate("#define BEGIN NS {");
+  EXPECT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::l_brace, TT_Unknown);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1571,7 +1571,8 @@
         } else if (Style.BraceWrapping.AfterFunction) {
           addUnwrappedLine();
         }
-        FormatTok->setType(TT_FunctionLBrace);
+        if (!Line->InPPDirective)
+          FormatTok->setType(TT_FunctionLBrace);
         parseBlock();
         addUnwrappedLine();
         return;


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===================================================================
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -91,6 +91,12 @@
   EXPECT_TOKEN(Tokens[2], tok::l_brace, TT_RecordLBrace);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsLBracesInMacroDefinition) {
+  auto Tokens = annotate("#define BEGIN NS {");
+  EXPECT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::l_brace, TT_Unknown);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1571,7 +1571,8 @@
         } else if (Style.BraceWrapping.AfterFunction) {
           addUnwrappedLine();
         }
-        FormatTok->setType(TT_FunctionLBrace);
+        if (!Line->InPPDirective)
+          FormatTok->setType(TT_FunctionLBrace);
         parseBlock();
         addUnwrappedLine();
         return;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to