This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG35f7dd601d33: [clang-format][NFC] Fix a bug in setting type FunctionLBrace (authored by owenpan).
Repository: rG LLVM Github Monorepo 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 @@ -1577,7 +1577,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 @@ -1577,7 +1577,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