]> granicus.if.org Git - clang/commitdiff
clang-format: Correctly detect multiplication in ctor initializer.
authorDaniel Jasper <djasper@google.com>
Fri, 14 Nov 2014 17:26:49 +0000 (17:26 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 14 Nov 2014 17:26:49 +0000 (17:26 +0000)
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

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

index 5234de2bb7d78d352fd165af9367335ed2fd9f9a..104eb1d7afb89d77c03bbb8d31ac247218a17da8 100644 (file)
@@ -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;
index 31984f6bfaf904c88404ba4384928d178897011a..540dd03b42eda4f9b725af6faeb00796fde13cd0 100644 (file)
@@ -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;");