From cbd13bc1edfe3c08b7e9012428acb0bc789b0f5f Mon Sep 17 00:00:00 2001 From: Nicholas Allegra Date: Tue, 17 Sep 2019 01:43:33 +0000 Subject: [PATCH] Push lambda scope earlier when transforming lambda expression Differential Revision: https://reviews.llvm.org/D66067 llvm-svn: 372058 --- clang/lib/Sema/TreeTransform.h | 8 ++++---- clang/test/SemaTemplate/default-arguments-cxx0x.cpp | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index c2a144a..beef7ca 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -11325,10 +11325,14 @@ TreeTransform::TransformLambdaExpr(LambdaExpr *E) { } } + LambdaScopeInfo *LSI = getSema().PushLambdaScope(); + Sema::FunctionScopeRAII FuncScopeCleanup(getSema()); + // Transform the template parameters, and add them to the current // instantiation scope. The null case is handled correctly. auto TPL = getDerived().TransformTemplateParameterList( E->getTemplateParameterList()); + LSI->GLTemplateParameterList = TPL; // Transform the type of the original lambda's call operator. // The transformation MUST be done in the CurrentInstantiationScope since @@ -11355,10 +11359,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr *E) { NewCallOpType); } - LambdaScopeInfo *LSI = getSema().PushLambdaScope(); - Sema::FunctionScopeRAII FuncScopeCleanup(getSema()); - LSI->GLTemplateParameterList = TPL; - // Create the local class that will describe the lambda. CXXRecordDecl *OldClass = E->getLambdaClass(); CXXRecordDecl *Class diff --git a/clang/test/SemaTemplate/default-arguments-cxx0x.cpp b/clang/test/SemaTemplate/default-arguments-cxx0x.cpp index c24ed12..2114cc9 100644 --- a/clang/test/SemaTemplate/default-arguments-cxx0x.cpp +++ b/clang/test/SemaTemplate/default-arguments-cxx0x.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s +// RUN: %clang_cc1 -fsyntax-only -std=c++14 -verify %s // expected-no-diagnostics // Test default template arguments for function templates. @@ -114,3 +115,17 @@ namespace rdar34167492 { S _a{}; }; } + +#if __cplusplus >= 201402L +namespace lambda { + // Verify that a default argument in a lambda can refer to the type of a + // previous `auto` argument without crashing. + template + void bar() { + (void) [](auto c, int x = sizeof(decltype(c))) {}; + } + void foo() { + bar(); + } +} // namespace lambda +#endif -- 2.7.4