r256175 - clang-format: Properly set the BlockKind for more blocks.

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 21 10:31:15 PST 2015


Author: djasper
Date: Mon Dec 21 12:31:15 2015
New Revision: 256175

URL: http://llvm.org/viewvc/llvm-project?rev=256175&view=rev
Log:
clang-format: Properly set the BlockKind for more blocks.

Before:
  void f() { struct Dummy { };
    f();
  }

After:
  void f() {
    struct Dummy {};
    f();
  }

Modified:
    cfe/trunk/lib/Format/UnwrappedLineParser.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=256175&r1=256174&r2=256175&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon Dec 21 12:31:15 2015
@@ -321,7 +321,7 @@ void UnwrappedLineParser::calculateBrace
   SmallVector<FormatToken *, 8> 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(boo
   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(boo
   if (MacroBlock ? !FormatTok->is(TT_MacroBlockEnd)
                  : !FormatTok->is(tok::r_brace)) {
     Line->Level = InitialLevel;
+    FormatTok->BlockKind = BK_Block;
     return;
   }
 

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=256175&r1=256174&r2=256175&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Dec 21 12:31:15 2015
@@ -313,7 +313,7 @@ TEST_F(FormatTest, FormatIfWithoutCompou
                "  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, FormatsBracedListsInC
                "                   bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb};");
 
   verifyNoCrash("a<,");
+  
+  // No braced initializer here.
+  verifyFormat("void f() {\n"
+               "  struct Dummy {};\n"
+               "  f(v);\n"
+               "}");
 }
 
 TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {




More information about the cfe-commits mailing list