clang-format: Fix bad multi-variable for-loop formatting.
authorDaniel Jasper <djasper@google.com>
Tue, 4 Oct 2016 20:18:25 +0000 (20:18 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 4 Oct 2016 20:18:25 +0000 (20:18 +0000)
Before:
  for (int*p, *q; p != q; p = p->next) {

After:
  for (int *p, *q; p != q; p = p->next) {

llvm-svn: 283246

clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

index 428a068..ae054dd 100644 (file)
@@ -2020,7 +2020,9 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
                                      Left.Previous->is(tok::r_paren)) ||
             (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
              (Style.PointerAlignment != FormatStyle::PAS_Left ||
-              (Line.IsMultiVariableDeclStmt && Left.NestingLevel == 0))));
+              (Line.IsMultiVariableDeclStmt &&
+               (Left.NestingLevel == 0 ||
+                (Left.NestingLevel == 1 && Line.First->is(tok::kw_for)))))));
   if (Right.is(TT_FunctionTypeLParen) && Left.isNot(tok::l_paren) &&
       (!Left.is(TT_PointerOrReference) ||
        (Style.PointerAlignment != FormatStyle::PAS_Right &&
index 06a7e7e..f04f5e5 100644 (file)
@@ -4803,6 +4803,7 @@ TEST_F(FormatTest, DeclarationsOfMultipleVariables) {
                "          *b = bbbbbbbbbbbbbbbbbbb, *d = ddddddddddddddddddd;",
                Style);
   verifyFormat("vector<int*> a, b;", Style);
+  verifyFormat("for (int *p, *q; p != q; p = p->next) {\n}", Style);
 }
 
 TEST_F(FormatTest, ConditionalExpressionsInBrackets) {