Răsfoiți Sursa

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
Daniel Jasper 10 ani în urmă
părinte
comite
c7ad4a250b
2 a modificat fișierele cu 2 adăugiri și 1 ștergeri
  1. 1 1
      lib/Format/TokenAnnotator.cpp
  2. 1 0
      unittests/Format/FormatTest.cpp

+ 1 - 1
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;

+ 1 - 0
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;");