Skip to content

[clang][Sema] Improve Sema::CheckCXXDefaultArguments #97338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1630,9 +1630,6 @@ void Sema::MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old) {
/// function declaration are well-formed according to C++
/// [dcl.fct.default].
void Sema::CheckCXXDefaultArguments(FunctionDecl *FD) {
unsigned NumParams = FD->getNumParams();
unsigned ParamIdx = 0;

// This checking doesn't make sense for explicit specializations; their
// default arguments are determined by the declaration we're specializing,
// not by FD.
Expand All @@ -1642,6 +1639,9 @@ void Sema::CheckCXXDefaultArguments(FunctionDecl *FD) {
if (FTD->isMemberSpecialization())
return;

unsigned NumParams = FD->getNumParams();
unsigned ParamIdx = 0;

// Find first parameter with a default argument
for (; ParamIdx < NumParams; ++ParamIdx) {
ParmVarDecl *Param = FD->getParamDecl(ParamIdx);
Expand All @@ -1654,21 +1654,19 @@ void Sema::CheckCXXDefaultArguments(FunctionDecl *FD) {
// with a default argument shall have a default argument supplied in this or
// a previous declaration, unless the parameter was expanded from a
// parameter pack, or shall be a function parameter pack.
for (; ParamIdx < NumParams; ++ParamIdx) {
for (++ParamIdx; ParamIdx < NumParams; ++ParamIdx) {
ParmVarDecl *Param = FD->getParamDecl(ParamIdx);
if (!Param->hasDefaultArg() && !Param->isParameterPack() &&
!(CurrentInstantiationScope &&
CurrentInstantiationScope->isLocalPackExpansion(Param))) {
if (Param->isInvalidDecl())
/* We already complained about this parameter. */;
else if (Param->getIdentifier())
Diag(Param->getLocation(),
diag::err_param_default_argument_missing_name)
if (Param->hasDefaultArg() || Param->isParameterPack() ||
(CurrentInstantiationScope &&
CurrentInstantiationScope->isLocalPackExpansion(Param)))
continue;
if (Param->isInvalidDecl())
/* We already complained about this parameter. */;
else if (Param->getIdentifier())
Diag(Param->getLocation(), diag::err_param_default_argument_missing_name)
<< Param->getIdentifier();
else
Diag(Param->getLocation(),
diag::err_param_default_argument_missing);
}
else
Diag(Param->getLocation(), diag::err_param_default_argument_missing);
}
}

Expand Down
Loading