Skip to content
Snippets Groups Projects
Commit 0e97d13b authored by Benjamin Kramer's avatar Benjamin Kramer
Browse files

[Sema] Diagnose default argument on a parameter pack.

This is ill-formed (and cannot be used anyways).

PR23028.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233376 91177308-0d34-0410-b5e6-96231b3b80d8
parent 4e5d822f
No related branches found
No related tags found
No related merge requests found
......@@ -2808,6 +2808,8 @@ def err_param_default_argument_member_template_redecl : Error<
"default arguments cannot be added to an out-of-line definition of a member "
"of a %select{class template|class template partial specialization|nested "
"class in a template}0">;
def err_param_default_argument_on_parameter_pack : Error<
"parameter pack cannot have a default argument">;
def err_uninitialized_member_for_assign : Error<
"cannot define the implicit copy assignment operator for %0, because "
"non-static %select{reference|const}1 member %2 can't use copy "
......
......@@ -316,8 +316,17 @@ Sema::ActOnParamDefaultArgument(Decl *param, SourceLocation EqualLoc,
if (DiagnoseUnexpandedParameterPack(DefaultArg, UPPC_DefaultArgument)) {
Param->setInvalidDecl();
return;
}
}
// C++11 [dcl.fct.default]p3
// A default argument expression [...] shall not be specified for a
// parameter pack.
if (Param->isParameterPack()) {
Diag(EqualLoc, diag::err_param_default_argument_on_parameter_pack)
<< DefaultArg->getSourceRange();
return;
}
// Check that the default argument is well-formed
CheckDefaultArgumentVisitor DefaultArgChecker(DefaultArg, this);
if (DefaultArgChecker.Visit(DefaultArg)) {
......
......@@ -14,3 +14,6 @@ struct X0 {
void mem8(int (*fp)(int) = (int (*)(int = 17))0); // expected-error{{default arguments can only be specified for parameters in a function declaration}}
};
template <typename... Ts>
void defaultpack(Ts... = 0) {} // expected-error{{parameter pack cannot have a default argument}}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment