From: Daniel Jasper Date: Fri, 14 Nov 2014 17:26:49 +0000 (+0000) Subject: clang-format: Correctly detect multiplication in ctor initializer. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c7ad4a250b860da295d9b3496bd10ce75c51a4cf;p=clang clang-format: Correctly detect multiplication in ctor initializer. Before: Constructor() : a(a), area(width *height) {} After: Constructor() : a(a), area(width * height) {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222010 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 5234de2bb7..104eb1d7af 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -763,7 +763,7 @@ private: Previous && Previous->isOneOf(tok::star, tok::amp); Previous = Previous->Previous) Previous->Type = TT_PointerOrReference; - Contexts.back().IsExpression = false; + Contexts.back().IsExpression = Contexts.back().InCtorInitializer; } else if (Current.Previous && Current.Previous->Type == TT_CtorInitializerColon) { Contexts.back().IsExpression = true; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 31984f6bfa..540dd03b42 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5008,6 +5008,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("int i{a * b};"); verifyIndependentOfContext("aaa && aaa->f();"); verifyIndependentOfContext("int x = ~*p;"); + verifyFormat("Constructor() : a(a), area(width * height) {}"); verifyIndependentOfContext("InvalidRegions[*R] = 0;");