]> granicus.if.org Git - clang/commitdiff
PR42587: diagnose unexpanded uses of a pack parameter of a generic
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 23 Aug 2019 01:41:48 +0000 (01:41 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 23 Aug 2019 01:41:48 +0000 (01:41 +0000)
lambda from within the lambda-declarator.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@369722 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaLambda.cpp
lib/Sema/SemaTemplateVariadic.cpp
test/SemaCXX/cxx1y-generic-lambdas-variadics.cpp

index e7c51a3e3d92fb580caa7b32790390afc684cdda..6938804e5f185c17320363a19db18fe5cda5ecea 100644 (file)
@@ -928,12 +928,12 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
 
     // Check for unexpanded parameter packs in the method type.
     if (MethodTyInfo->getType()->containsUnexpandedParameterPack())
-      ContainsUnexpandedParameterPack = true;
+      DiagnoseUnexpandedParameterPack(Intro.Range.getBegin(), MethodTyInfo,
+                                      UPPC_DeclarationType);
   }
 
   CXXRecordDecl *Class = createLambdaClosureType(Intro.Range, MethodTyInfo,
                                                  KnownDependent, Intro.Default);
-
   CXXMethodDecl *Method =
       startLambdaDefinition(Class, Intro.Range, MethodTyInfo, EndLoc, Params,
                             ParamInfo.getDeclSpec().getConstexprSpecifier());
index f90bff6e7acfd32d3278b15f7c052e5a19511f67..b766e3c5686f74af5ef0b2040bb4f028a661e889 100644 (file)
@@ -313,10 +313,17 @@ Sema::DiagnoseUnexpandedParameterPacks(SourceLocation Loc,
 
     if (auto *LSI = dyn_cast<sema::LambdaScopeInfo>(Func)) {
       if (N == FunctionScopes.size()) {
+        const DeclContext *LambdaDC = LSI->CallOperator;
+        // While we're parsing the lambda-declarator, we don't have a call
+        // operator yet and the parameters instead get temporarily attached
+        // to the translation unit.
+        if (!LambdaDC)
+          LambdaDC = Context.getTranslationUnitDecl();
+
         for (auto &Pack : Unexpanded) {
           auto *VD = dyn_cast_or_null<VarDecl>(
               Pack.first.dyn_cast<NamedDecl *>());
-          if (VD && VD->getDeclContext() == LSI->CallOperator)
+          if (VD && VD->getDeclContext() == LambdaDC)
             LambdaParamPackReferences.push_back(Pack);
         }
       }
index b8022d209122e74dda6bdef2030d6e16319c43f2..22afdc08d9a45fb570e47812cfe81477d63cf189 100644 (file)
@@ -122,3 +122,11 @@ namespace PR33082 {
     b(Pack<int*, float*>(), 1, 2, 3); // expected-note {{instantiation of}}
   }
 }
+
+void pr42587() {
+  (void)[](auto... args) -> decltype(args) {}; // expected-error {{type contains unexpanded parameter pack}}
+  (void)[](auto... args, int = args) {}; // expected-error {{default argument contains unexpanded parameter pack}}
+  (void)[](auto... args, decltype(args)) {}; // expected-error {{type contains unexpanded parameter pack}}
+  (void)[](auto... args, decltype(args)...) {}; // (ok)
+  (void)[](auto... args, int = [=] { return args; }()) {}; // expected-error {{default argument contains unexpanded parameter pack}}
+}