diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1337,14 +1337,15 @@ if (CurrentToken && CurrentToken->isOneOf(Keywords.kw_mark, Keywords.kw_option, Keywords.kw_region)) { - bool IsMark = CurrentToken->is(Keywords.kw_mark); + bool IsMarkOrRegion = + CurrentToken->isOneOf(Keywords.kw_mark, Keywords.kw_region); next(); next(); // Consume first token (so we fix leading whitespace). while (CurrentToken) { - if (IsMark || CurrentToken->Previous->is(TT_BinaryOperator)) + if (IsMarkOrRegion || CurrentToken->Previous->is(TT_BinaryOperator)) { CurrentToken->setType(TT_ImplicitStringLiteral); next(); - } + } } } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -19965,9 +19965,7 @@ TEST_F(FormatTest, UnderstandPragmaRegion) { auto Style = getLLVMStyleWithColumns(0); verifyFormat("#pragma region TEST(FOO : BAR)", Style); - - EXPECT_EQ("#pragma region TEST(FOO : BAR)", - format("#pragma region TEST(FOO : BAR)", Style)); + verifyFormat("#pragma region TEST(FOO: NOSPACE)", Style); } TEST_F(FormatTest, OptimizeBreakPenaltyVsExcess) { 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 @@ -649,6 +649,22 @@ EXPECT_TOKEN(Tokens[14], tok::l_brace, TT_RequiresExpressionLBrace); } +TEST_F(TokenAnnotatorTest, UnderstandsPragmaRegion) { + // Everything after #pragma region should be ImplicitStringLiteral + auto Tokens = annotate("#pragma region Foo(Bar: Hello)"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; + EXPECT_TOKEN(Tokens[5], tok::identifier, TT_ImplicitStringLiteral); + EXPECT_TOKEN(Tokens[6], tok::colon, TT_ImplicitStringLiteral); + EXPECT_TOKEN(Tokens[7], tok::identifier, TT_ImplicitStringLiteral); + + // Make sure it's annotated correctly inside a function as well + Tokens = annotate("void test(){\n#pragma region Foo(Bar: Hello)\n}"); + ASSERT_EQ(Tokens.size(), 16u) << Tokens; + EXPECT_TOKEN(Tokens[10], tok::identifier, TT_ImplicitStringLiteral); + EXPECT_TOKEN(Tokens[11], tok::colon, TT_ImplicitStringLiteral); + EXPECT_TOKEN(Tokens[12], tok::identifier, TT_ImplicitStringLiteral); +} + TEST_F(TokenAnnotatorTest, RequiresDoesNotChangeParsingOfTheRest) { const char *BaseCode = nullptr; const char *ConstrainedCode = nullptr;