Author: comex Date: Mon Sep 16 18:43:33 2019 New Revision: 372058 URL: http://llvm.org/viewvc/llvm-project?rev=372058&view=rev Log: Push lambda scope earlier when transforming lambda expression
Differential Revision: https://reviews.llvm.org/D66067 Modified: cfe/trunk/lib/Sema/TreeTransform.h cfe/trunk/test/SemaTemplate/default-arguments-cxx0x.cpp Modified: cfe/trunk/lib/Sema/TreeTransform.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=372058&r1=372057&r2=372058&view=diff ============================================================================== --- cfe/trunk/lib/Sema/TreeTransform.h (original) +++ cfe/trunk/lib/Sema/TreeTransform.h Mon Sep 16 18:43:33 2019 @@ -11325,10 +11325,14 @@ TreeTransform<Derived>::TransformLambdaE } } + 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<Derived>::TransformLambdaE 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 Modified: cfe/trunk/test/SemaTemplate/default-arguments-cxx0x.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/default-arguments-cxx0x.cpp?rev=372058&r1=372057&r2=372058&view=diff ============================================================================== --- cfe/trunk/test/SemaTemplate/default-arguments-cxx0x.cpp (original) +++ cfe/trunk/test/SemaTemplate/default-arguments-cxx0x.cpp Mon Sep 16 18:43:33 2019 @@ -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<int> _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 <class T> + void bar() { + (void) [](auto c, int x = sizeof(decltype(c))) {}; + } + void foo() { + bar<int>(); + } +} // namespace lambda +#endif _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits