From e4ab49e8d3cfd1556b61d4af79fede0e477ebfb0 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 20 Apr 2015 12:54:29 +0000 Subject: [PATCH] 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) {} llvm-svn: 235301 --- clang/lib/Format/TokenAnnotator.cpp | 6 +++--- clang/unittests/Format/FormatTest.cpp | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 5b148eab6b13..ea5503ade68d 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 9791e2a5fb95..bec7a9cfb50a 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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;");