]> granicus.if.org Git - clang/commitdiff
[Sema] Maintain ellipsis location when transforming lambda captures
authorMeador Inge <meadori@codesourcery.com>
Fri, 26 Jun 2015 00:09:55 +0000 (00:09 +0000)
committerMeador Inge <meadori@codesourcery.com>
Fri, 26 Jun 2015 00:09:55 +0000 (00:09 +0000)
This patch fixes a crash caused by the following case:

  template<typename T>
  auto f(T x) {
    auto g = [](auto ... args) {
      auto h = [args...]() -> int {
        return 0;
      };
      return h;
    };
    return g;
  }

  auto x = f(0)();

When the templated function 'f' is instantiated and the inner-most
lambda is transformed the ellipsis location on the captured variable
is lost.  Then the lambda returned by 'f' is instantiated and the
tree transformer chokes on the invalid ellipsis location.  The
problem is fixed by making a minor change to properly track the
ellipsis location.

This fixes PR23716.

Differential Revision: http://reviews.llvm.org/D10590

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

lib/Sema/TreeTransform.h
test/SemaCXX/cxx1y-generic-lambdas.cpp

index 3b2a17c54973e0b7dfb3a74e11e2870d5ff52211..5d9c35f08df5dfb0904b4b8f4ac1b6ab09b36241 100644 (file)
@@ -9399,7 +9399,8 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
     }
 
     // Capture the transformed variable.
-    getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
+    getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
+                                 EllipsisLoc);
   }
   if (!FinishedExplicitCaptures)
     getSema().finishLambdaExplicitCaptures(LSI);
index f4c67fbba0cd8574ba5ec685b05b19899c779d87..b49a6418ea8575d33b4286aba6aead1005249f75 100644 (file)
@@ -933,3 +933,18 @@ namespace PR22117 {
     };
   }(0)(0);
 }
+
+namespace PR23716 {
+template<typename T>
+auto f(T x) {
+  auto g = [](auto&&... args) {
+    auto h = [args...]() -> int {
+      return 0;
+    };
+    return h;
+  };
+  return g;
+}
+
+auto x = f(0)();
+}