From: Richard Smith Date: Fri, 23 Aug 2019 01:41:48 +0000 (+0000) Subject: PR42587: diagnose unexpanded uses of a pack parameter of a generic X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=148028f12f2c1ece09e75344d88d2f96aafb4d9a;p=clang PR42587: diagnose unexpanded uses of a pack parameter of a generic lambda from within the lambda-declarator. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@369722 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaLambda.cpp b/lib/Sema/SemaLambda.cpp index e7c51a3e3d..6938804e5f 100644 --- a/lib/Sema/SemaLambda.cpp +++ b/lib/Sema/SemaLambda.cpp @@ -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()); diff --git a/lib/Sema/SemaTemplateVariadic.cpp b/lib/Sema/SemaTemplateVariadic.cpp index f90bff6e7a..b766e3c568 100644 --- a/lib/Sema/SemaTemplateVariadic.cpp +++ b/lib/Sema/SemaTemplateVariadic.cpp @@ -313,10 +313,17 @@ Sema::DiagnoseUnexpandedParameterPacks(SourceLocation Loc, if (auto *LSI = dyn_cast(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( Pack.first.dyn_cast()); - if (VD && VD->getDeclContext() == LSI->CallOperator) + if (VD && VD->getDeclContext() == LambdaDC) LambdaParamPackReferences.push_back(Pack); } } diff --git a/test/SemaCXX/cxx1y-generic-lambdas-variadics.cpp b/test/SemaCXX/cxx1y-generic-lambdas-variadics.cpp index b8022d2091..22afdc08d9 100644 --- a/test/SemaCXX/cxx1y-generic-lambdas-variadics.cpp +++ b/test/SemaCXX/cxx1y-generic-lambdas-variadics.cpp @@ -122,3 +122,11 @@ namespace PR33082 { b(Pack(), 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}} +}