Skip to content

Commit 4f9dee7

Browse files
committed
[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 llvm-svn: 240740
1 parent 459a23e commit 4f9dee7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

clang/lib/Sema/TreeTransform.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9399,7 +9399,8 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
93999399
}
94009400

94019401
// Capture the transformed variable.
9402-
getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9402+
getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
9403+
EllipsisLoc);
94039404
}
94049405
if (!FinishedExplicitCaptures)
94059406
getSema().finishLambdaExplicitCaptures(LSI);

clang/test/SemaCXX/cxx1y-generic-lambdas.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,3 +933,18 @@ namespace PR22117 {
933933
};
934934
}(0)(0);
935935
}
936+
937+
namespace PR23716 {
938+
template<typename T>
939+
auto f(T x) {
940+
auto g = [](auto&&... args) {
941+
auto h = [args...]() -> int {
942+
return 0;
943+
};
944+
return h;
945+
};
946+
return g;
947+
}
948+
949+
auto x = f(0)();
950+
}

0 commit comments

Comments
 (0)