From: Daniel Jasper Date: Mon, 21 Dec 2015 18:31:15 +0000 (+0000) Subject: clang-format: Properly set the BlockKind for more blocks. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b8cc716acd20e16ef3a8e66d6c561a4971330c0c;p=clang clang-format: Properly set the BlockKind for more blocks. Before: void f() { struct Dummy { }; f(); } After: void f() { struct Dummy {}; f(); } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256175 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index e06903c306..ac534a2abe 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -321,7 +321,7 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) { SmallVector LBraceStack; assert(Tok->Tok.is(tok::l_brace)); do { - // Get next none-comment token. + // Get next non-comment token. FormatToken *NextTok; unsigned ReadTokens = 0; do { @@ -403,6 +403,7 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel, assert(FormatTok->isOneOf(tok::l_brace, TT_MacroBlockBegin) && "'{' or macro block token expected"); const bool MacroBlock = FormatTok->is(TT_MacroBlockBegin); + FormatTok->BlockKind = BK_Block; unsigned InitialLevel = Line->Level; nextToken(); @@ -421,6 +422,7 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel, if (MacroBlock ? !FormatTok->is(TT_MacroBlockEnd) : !FormatTok->is(tok::r_brace)) { Line->Level = InitialLevel; + FormatTok->BlockKind = BK_Block; return; } diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 1f09ee3d51..6245f8c043 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -313,7 +313,7 @@ TEST_F(FormatTest, FormatIfWithoutCompoundStatement) { " f();\n" "}", AllowsMergedIf); - verifyFormat("if (a) {/* Never merge this */\n" + verifyFormat("if (a) { /* Never merge this */\n" " f();\n" "}", AllowsMergedIf); @@ -6532,6 +6532,12 @@ TEST_F(FormatTest, FormatsBracedListsInColumnLayout) { " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb};"); verifyNoCrash("a<,"); + + // No braced initializer here. + verifyFormat("void f() {\n" + " struct Dummy {};\n" + " f(v);\n" + "}"); } TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {