From eb65e912aaa0cb0bb7adf138495f3e25fb2ecdf6 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 21 Dec 2015 18:31:15 +0000 Subject: clang-format: Properly set the BlockKind for more blocks. Before: void f() { struct Dummy { }; f(); } After: void f() { struct Dummy {}; f(); } llvm-svn: 256175 --- clang/lib/Format/UnwrappedLineParser.cpp | 4 +++- clang/unittests/Format/FormatTest.cpp | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'clang') diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index e06903c306c..ac534a2abe5 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 1f09ee3d513..6245f8c0434 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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) { -- cgit v1.2.3