From: Daniel Jasper Date: Mon, 20 Apr 2015 12:54:29 +0000 (+0000) Subject: clang-format: Fix incorrect multi-var declstmt detection. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0600b1e0dbd549e1d209a455d6c0464f14990134;p=clang clang-format: Fix incorrect multi-var declstmt detection. This is now obvious as the pointer alignment behavior was changed. Before (even with pointer alignment "Left"): MACRO Constructor(const int &i) : a(a), b(b) {} After: MACRO Constructor(const int& i) : a(a), b(b) {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235301 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 5b148eab6b..ea5503ade6 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -543,12 +543,12 @@ private: parseTemplateDeclaration(); break; case tok::comma: - if (Contexts.back().FirstStartOfName && Contexts.size() == 1) { + if (Contexts.back().InCtorInitializer) + Tok->Type = TT_CtorInitializerComma; + else if (Contexts.back().FirstStartOfName && Contexts.size() == 1) { Contexts.back().FirstStartOfName->PartOfMultiVariableDeclStmt = true; Line.IsMultiVariableDeclStmt = true; } - if (Contexts.back().InCtorInitializer) - Tok->Type = TT_CtorInitializerComma; if (Contexts.back().IsForEachMacro) Contexts.back().IsExpression = true; break; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 9791e2a5fb..bec7a9cfb5 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5336,6 +5336,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("int x = ~*p;"); verifyFormat("Constructor() : a(a), area(width * height) {}"); verifyFormat("Constructor() : a(a), area(a, width * height) {}"); + verifyGoogleFormat("MACRO Constructor(const int& i) : a(a), b(b) {}"); verifyFormat("void f() { f(a, c * d); }"); verifyIndependentOfContext("InvalidRegions[*R] = 0;");