From: Meador Inge Date: Fri, 26 Jun 2015 00:09:55 +0000 (+0000) Subject: [Sema] Maintain ellipsis location when transforming lambda captures X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a6b6dbe12e6ff2986d3c1a9b6627a9e2978a20dd;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240740 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 3b2a17c549..5d9c35f08d 100644 --- a/lib/Sema/TreeTransform.h +++ b/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/test/SemaCXX/cxx1y-generic-lambdas.cpp b/test/SemaCXX/cxx1y-generic-lambdas.cpp index f4c67fbba0..b49a6418ea 100644 --- a/test/SemaCXX/cxx1y-generic-lambdas.cpp +++ b/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)(); +}