summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2019-08-23 01:41:48 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2019-08-23 01:41:48 +0000
commit7fbadf3b2793bf907d5a1fb7c1c9078500a0b030 (patch)
treeb392e7dc108253ae8874d6903d47e2b15def9d71
parent21a181441724fe81a24ee4cdb540f7c62e33231c (diff)
downloadbcm5719-llvm-7fbadf3b2793bf907d5a1fb7c1c9078500a0b030.tar.gz
bcm5719-llvm-7fbadf3b2793bf907d5a1fb7c1c9078500a0b030.zip
PR42587: diagnose unexpanded uses of a pack parameter of a generic
lambda from within the lambda-declarator. llvm-svn: 369722
-rw-r--r--clang/lib/Sema/SemaLambda.cpp4
-rw-r--r--clang/lib/Sema/SemaTemplateVariadic.cpp9
-rw-r--r--clang/test/SemaCXX/cxx1y-generic-lambdas-variadics.cpp8
3 files changed, 18 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index e7c51a3e3d9..6938804e5f1 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/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/clang/lib/Sema/SemaTemplateVariadic.cpp b/clang/lib/Sema/SemaTemplateVariadic.cpp
index f90bff6e7ac..b766e3c5686 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -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);
}
}
diff --git a/clang/test/SemaCXX/cxx1y-generic-lambdas-variadics.cpp b/clang/test/SemaCXX/cxx1y-generic-lambdas-variadics.cpp
index b8022d20912..22afdc08d9a 100644
--- a/clang/test/SemaCXX/cxx1y-generic-lambdas-variadics.cpp
+++ b/clang/test/SemaCXX/cxx1y-generic-lambdas-variadics.cpp
@@ -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}}
+}
OpenPOWER on IntegriCloud