From 4f9dee7511473c86b8e22f76dfc6ed569314e017 Mon Sep 17 00:00:00 2001 From: Meador Inge Date: Fri, 26 Jun 2015 00:09:55 +0000 Subject: [PATCH] [Sema] Maintain ellipsis location when transforming lambda captures This patch fixes a crash caused by the following case: template 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 --- clang/lib/Sema/TreeTransform.h | 3 ++- clang/test/SemaCXX/cxx1y-generic-lambdas.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 3b2a17c..5d9c35f 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -9399,7 +9399,8 @@ TreeTransform::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); diff --git a/clang/test/SemaCXX/cxx1y-generic-lambdas.cpp b/clang/test/SemaCXX/cxx1y-generic-lambdas.cpp index f4c67fb..b49a641 100644 --- a/clang/test/SemaCXX/cxx1y-generic-lambdas.cpp +++ b/clang/test/SemaCXX/cxx1y-generic-lambdas.cpp @@ -933,3 +933,18 @@ namespace PR22117 { }; }(0)(0); } + +namespace PR23716 { +template +auto f(T x) { + auto g = [](auto&&... args) { + auto h = [args...]() -> int { + return 0; + }; + return h; + }; + return g; +} + +auto x = f(0)(); +} -- 2.7.4