]> granicus.if.org Git - clang/commitdiff
Fix incorrect token counting introduced by r185319.
authorDaniel Jasper <djasper@google.com>
Mon, 1 Jul 2013 16:43:38 +0000 (16:43 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 1 Jul 2013 16:43:38 +0000 (16:43 +0000)
This lead to weird formatting.
Before:
DoSomethingWithVector({ {} /* No data */ }, {
  { 1, 2 }
});
After:
DoSomethingWithVector({ {} /* No data */ }, { { 1, 2 } });

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

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

index 170c89260917dd271184eb500b0fb10a7310eae2..98a5a8ae075cc8c2b3e6fbf8dbb230bd8a293476 100644 (file)
@@ -257,8 +257,10 @@ void UnwrappedLineParser::calculateBraceTypes() {
   do {
     // Get next none-comment token.
     FormatToken *NextTok;
+    unsigned ReadTokens = 0;
     do {
       NextTok = Tokens->getNextToken();
+      ++ReadTokens;
     } while (NextTok->is(tok::comment));
 
     switch (Tok->Tok.getKind()) {
@@ -298,7 +300,7 @@ void UnwrappedLineParser::calculateBraceTypes() {
       break;
     }
     Tok = NextTok;
-    ++Position;
+    Position += ReadTokens;
   } while (Tok->Tok.isNot(tok::eof));
   // Assume other blocks for all unclosed opening braces.
   for (unsigned i = 0, e = LBraceStack.size(); i != e; ++i) {
index affec47121482d5661065f5c341cf3e5f9eaefea..6df7e9b0e935df1b131924e35e5d8d1a58e5aaf1 100644 (file)
@@ -3683,6 +3683,7 @@ TEST_F(FormatTest, LayoutCxx11ConstructorBraceInitializers) {
         "                  : vector<int>{ bbbbbbbbbbbbbbbbbbbbbbbbbbb,\n"
         "                                 bbbbbbbbbbbbbbbbbbbb, bbbbb };");
     verifyFormat("DoSomethingWithVector({} /* No data */);");
+    verifyFormat("DoSomethingWithVector({ {} /* No data */ }, { { 1, 2 } });");
 
     FormatStyle NoSpaces = getLLVMStyle();
     NoSpaces.SpacesInBracedLists = false;