]> granicus.if.org Git - clang/commitdiff
clang-format: Fix incorrect pointer detection in lambdas in constructor
authorDaniel Jasper <djasper@google.com>
Mon, 1 Feb 2016 11:21:07 +0000 (11:21 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 1 Feb 2016 11:21:07 +0000 (11:21 +0000)
initializers.

Before:
  Constructor() : member([](A *a, B * b) {}) {}

After:
  Constructor() : member([](A *a, B *b) {}) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259353 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 6d02557dd9cfef90a43fdb2e1ebc59233eaaafa8..371c6a3a830d043fa50ced098d6b272b619852a4 100644 (file)
@@ -887,8 +887,8 @@ private:
            Previous && Previous->isOneOf(tok::star, tok::amp);
            Previous = Previous->Previous)
         Previous->Type = TT_PointerOrReference;
-      if (Line.MustBeDeclaration)
-        Contexts.back().IsExpression = Contexts.front().InCtorInitializer;
+      if (Line.MustBeDeclaration && !Contexts.front().InCtorInitializer)
+        Contexts.back().IsExpression = false;
     } else if (Current.Previous &&
                Current.Previous->is(TT_CtorInitializerColon)) {
       Contexts.back().IsExpression = true;
index 17db98fe79f15c2126dd245cce17bcc58cb38ec4..ad355398508bc41ff8ebd8227f0536f6cc7ac58b 100644 (file)
@@ -5634,6 +5634,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyFormat("[](const decltype(*a) &value) {}");
   verifyFormat("decltype(a * b) F();");
   verifyFormat("#define MACRO() [](A *a) { return 1; }");
+  verifyFormat("Constructor() : member([](A *a, B *b) {}) {}");
   verifyIndependentOfContext("typedef void (*f)(int *a);");
   verifyIndependentOfContext("int i{a * b};");
   verifyIndependentOfContext("aaa && aaa->f();");