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 @@ -751,6 +751,11 @@ if (!LBraceStack.empty() && LBraceStack.back()->is(BK_Unknown)) LBraceStack.back()->setBlockKind(BK_Block); break; + case tok::hash: + do { + NextTok = Tokens->getNextToken(); + } while (NextTok->isNot(tok::eof)); + break; default: break; } 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 @@ -19970,6 +19970,14 @@ format("#pragma region TEST(FOO : BAR)", Style)); } +TEST_F(FormatTest, PragmaRegionShouldNotBeBraceInitializers) { + auto Style = getLLVMStyleWithColumns(0); + verifyFormat("CxxClass::CxxClass() {\n#pragma region test(hello)\n}", Style); + EXPECT_EQ("CxxClass::CxxClass()\n#pragma region TEST(bar: foo)\n{\n#pragma region TEST(foo: bar)\n#pragma endregion\n}\nCxxClass *Hello() {}", + format("CxxClass::CxxClass()\n#pragma region TEST(bar: foo)\n{\n #pragma region TEST(foo: bar)\n #pragma endregion\n}\nCxxClass* Hello()\n{}", Style)); + +} + TEST_F(FormatTest, OptimizeBreakPenaltyVsExcess) { FormatStyle Style = getLLVMStyleWithColumns(20);