From: Daniel Jasper Date: Mon, 18 May 2015 14:49:19 +0000 (+0000) Subject: clang-format: Fix another regression caused by r237565. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6219f10c6f7200df306c742957436912c2d53c0c;p=clang clang-format: Fix another regression caused by r237565. Before: class C : test { class D : test{void f(){int i{2}; } } ; } ; After: class C : test { class D : test { void f() { int i{2}; } }; }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237569 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 2331305cc5..5b1a448567 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -325,6 +325,7 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) { switch (Tok->Tok.getKind()) { case tok::l_brace: + Tok->BlockKind = BK_Unknown; LBraceStack.push_back(Tok); break; case tok::r_brace: @@ -1017,9 +1018,9 @@ void UnwrappedLineParser::tryToParseJSFunction() { parseChildBlock(); } -bool UnwrappedLineParser::tryToParseBracedList(bool ExpectClassBody) { +bool UnwrappedLineParser::tryToParseBracedList() { if (FormatTok->BlockKind == BK_Unknown) - calculateBraceTypes(ExpectClassBody); + calculateBraceTypes(); assert(FormatTok->BlockKind != BK_Unknown); if (FormatTok->BlockKind == BK_Block) return false; @@ -1573,9 +1574,11 @@ void UnwrappedLineParser::parseRecord() { // and class declarations). if (FormatTok->isOneOf(tok::colon, tok::less)) { while (!eof()) { - if (FormatTok->is(tok::l_brace) && - !tryToParseBracedList(/*ExpectClassBody=*/true)) - break; + if (FormatTok->is(tok::l_brace)) { + calculateBraceTypes(/*ExpectClassBody=*/true); + if (!tryToParseBracedList()) + break; + } if (FormatTok->Tok.is(tok::semi)) return; nextToken(); diff --git a/lib/Format/UnwrappedLineParser.h b/lib/Format/UnwrappedLineParser.h index a75845f5d8..c2fa029576 100644 --- a/lib/Format/UnwrappedLineParser.h +++ b/lib/Format/UnwrappedLineParser.h @@ -82,7 +82,7 @@ private: void parsePPEndIf(); void parsePPUnknown(); void parseStructuralElement(); - bool tryToParseBracedList(bool ExpectClassBody = false); + bool tryToParseBracedList(); bool parseBracedList(bool ContinueOnSemicolons = false); void parseParens(); void parseSquare(); @@ -113,7 +113,7 @@ private: void readToken(); void flushComments(bool NewlineBeforeNext); void pushToken(FormatToken *Tok); - void calculateBraceTypes(bool ExpectClassBody); + void calculateBraceTypes(bool ExpectClassBody = false); // Marks a conditional compilation edge (for example, an '#if', '#ifdef', // '#else' or merge conflict marker). If 'Unreachable' is true, assumes diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 0bb1bc151a..ab09e0075d 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -6195,6 +6195,11 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) { verifyFormat("class C : public D {\n" " SomeClass SC{2};\n" "};"); + verifyFormat("class C : public A {\n" + " class D : public B {\n" + " void f() { int i{2}; }\n" + " };\n" + "};"); // In combination with BinPackParameters = false. FormatStyle NoBinPacking = getLLVMStyle();