diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/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; diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/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