Author: meadori
Date: Thu Jun 25 19:09:55 2015
New Revision: 240740
URL: http://llvm.org/viewvc/llvm-project?rev=240740&view=rev
Log:
[Sema] Maintain ellipsis location when transforming lambda captures
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
Modified:
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/SemaCXX/cxx1y-generic-lambdas.cpp
Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=240740&r1=240739&r2=240740&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Thu Jun 25 19:09:55 2015
@@ -9399,7 +9399,8 @@ TreeTransform<Derived>::TransformLambdaE
}
// Capture the transformed variable.
- getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
+ getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
+ EllipsisLoc);
}
if (!FinishedExplicitCaptures)
getSema().finishLambdaExplicitCaptures(LSI);
Modified: cfe/trunk/test/SemaCXX/cxx1y-generic-lambdas.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1y-generic-lambdas.cpp?rev=240740&r1=240739&r2=240740&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx1y-generic-lambdas.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx1y-generic-lambdas.cpp Thu Jun 25 19:09:55 2015
@@ -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)();
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits