]> granicus.if.org Git - clang/commitdiff
Fix braced-list detection in lieu of trailing comments.
authorDaniel Jasper <djasper@google.com>
Mon, 1 Jul 2013 09:15:46 +0000 (09:15 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 1 Jul 2013 09:15:46 +0000 (09:15 +0000)
Before:
DoSomethingWithVector({
} /* No data */);
After:
DoSomethingWithVector({} /* No data */);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185319 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp

index 1c2a8fe4889ceee8cf9a36333cff011f829c38e2..170c89260917dd271184eb500b0fb10a7310eae2 100644 (file)
@@ -255,7 +255,12 @@ void UnwrappedLineParser::calculateBraceTypes() {
   SmallVector<unsigned, 8> LBraceStack;
   assert(Tok->Tok.is(tok::l_brace));
   do {
-    FormatToken *NextTok = Tokens->getNextToken();
+    // Get next none-comment token.
+    FormatToken *NextTok;
+    do {
+      NextTok = Tokens->getNextToken();
+    } while (NextTok->is(tok::comment));
+
     switch (Tok->Tok.getKind()) {
     case tok::l_brace:
       LBraceStack.push_back(Position);
index 682aa522231caf9bbe52344830e08aa5f0921e44..c4d9c6f573b48cc5206e6fa09eac9645b7e8d74e 100644 (file)
@@ -3641,6 +3641,7 @@ TEST_F(FormatTest, LayoutCxx11ConstructorBraceInitializers) {
         "                                 aaaaaaaaaaaaaaaaaaaa, aaaaa }\n"
         "                  : vector<int>{ bbbbbbbbbbbbbbbbbbbbbbbbbbb,\n"
         "                                 bbbbbbbbbbbbbbbbbbbb, bbbbb };");
+    verifyFormat("DoSomethingWithVector({} /* No data */);");
 
     FormatStyle NoSpaces = getLLVMStyle();
     NoSpaces.SpacesInBracedLists = false;