Skip to content

Commit bc8a8f5

Browse files
[clang][Sema] Improve Sema::CheckCXXDefaultArguments (#97338)
In the second loop in `Sema::CheckCXXDefaultArguments`, we don't need to re-examine the first parameter with a default argument. Dropped the first iteration of that loop. In addition, use the preferred early `continue` for the if-statement in the loop.
1 parent 64f67a4 commit bc8a8f5

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,9 +1630,6 @@ void Sema::MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old) {
16301630
/// function declaration are well-formed according to C++
16311631
/// [dcl.fct.default].
16321632
void Sema::CheckCXXDefaultArguments(FunctionDecl *FD) {
1633-
unsigned NumParams = FD->getNumParams();
1634-
unsigned ParamIdx = 0;
1635-
16361633
// This checking doesn't make sense for explicit specializations; their
16371634
// default arguments are determined by the declaration we're specializing,
16381635
// not by FD.
@@ -1642,6 +1639,9 @@ void Sema::CheckCXXDefaultArguments(FunctionDecl *FD) {
16421639
if (FTD->isMemberSpecialization())
16431640
return;
16441641

1642+
unsigned NumParams = FD->getNumParams();
1643+
unsigned ParamIdx = 0;
1644+
16451645
// Find first parameter with a default argument
16461646
for (; ParamIdx < NumParams; ++ParamIdx) {
16471647
ParmVarDecl *Param = FD->getParamDecl(ParamIdx);
@@ -1654,21 +1654,19 @@ void Sema::CheckCXXDefaultArguments(FunctionDecl *FD) {
16541654
// with a default argument shall have a default argument supplied in this or
16551655
// a previous declaration, unless the parameter was expanded from a
16561656
// parameter pack, or shall be a function parameter pack.
1657-
for (; ParamIdx < NumParams; ++ParamIdx) {
1657+
for (++ParamIdx; ParamIdx < NumParams; ++ParamIdx) {
16581658
ParmVarDecl *Param = FD->getParamDecl(ParamIdx);
1659-
if (!Param->hasDefaultArg() && !Param->isParameterPack() &&
1660-
!(CurrentInstantiationScope &&
1661-
CurrentInstantiationScope->isLocalPackExpansion(Param))) {
1662-
if (Param->isInvalidDecl())
1663-
/* We already complained about this parameter. */;
1664-
else if (Param->getIdentifier())
1665-
Diag(Param->getLocation(),
1666-
diag::err_param_default_argument_missing_name)
1659+
if (Param->hasDefaultArg() || Param->isParameterPack() ||
1660+
(CurrentInstantiationScope &&
1661+
CurrentInstantiationScope->isLocalPackExpansion(Param)))
1662+
continue;
1663+
if (Param->isInvalidDecl())
1664+
/* We already complained about this parameter. */;
1665+
else if (Param->getIdentifier())
1666+
Diag(Param->getLocation(), diag::err_param_default_argument_missing_name)
16671667
<< Param->getIdentifier();
1668-
else
1669-
Diag(Param->getLocation(),
1670-
diag::err_param_default_argument_missing);
1671-
}
1668+
else
1669+
Diag(Param->getLocation(), diag::err_param_default_argument_missing);
16721670
}
16731671
}
16741672

0 commit comments

Comments
 (0)