소스 검색

Push lambda scope earlier when transforming lambda expression

Differential Revision: https://reviews.llvm.org/D66067



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@372058 91177308-0d34-0410-b5e6-96231b3b80d8
Nicholas Allegra 6 년 전
부모
커밋
c222ee13b5
2개의 변경된 파일19개의 추가작업 그리고 4개의 파일을 삭제
  1. 4 4
      lib/Sema/TreeTransform.h
  2. 15 0
      test/SemaTemplate/default-arguments-cxx0x.cpp

+ 4 - 4
lib/Sema/TreeTransform.h

@@ -11325,10 +11325,14 @@ TreeTransform<Derived>::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<Derived>::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

+ 15 - 0
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<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