From: Daniel Jasper Date: Tue, 4 Oct 2016 20:18:25 +0000 (+0000) Subject: clang-format: Fix bad multi-variable for-loop formatting. X-Git-Tag: llvmorg-4.0.0-rc1~8123 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=85d1f0b6104675ad46a0d2551ed11a8bc3467d61;p=platform%2Fupstream%2Fllvm.git clang-format: Fix bad multi-variable for-loop formatting. Before: for (int*p, *q; p != q; p = p->next) { After: for (int *p, *q; p != q; p = p->next) { llvm-svn: 283246 --- diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 428a068..ae054dd 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -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 && diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 06a7e7e..f04f5e5 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -4803,6 +4803,7 @@ TEST_F(FormatTest, DeclarationsOfMultipleVariables) { " *b = bbbbbbbbbbbbbbbbbbb, *d = ddddddddddddddddddd;", Style); verifyFormat("vector a, b;", Style); + verifyFormat("for (int *p, *q; p != q; p = p->next) {\n}", Style); } TEST_F(FormatTest, ConditionalExpressionsInBrackets) {