Skip to content

Commit 679be52

Browse files
authored
[Clang][NFC] Consolidate the parameter check for the requires expression parameter. (#110773)
This patch is a follow-up to #109831. In the discussion, we agreed that having parameter checks scattered across different areas isn't ideal. Therefore, I suggest merging the check from #88974 into the void parameter check. This change won't impact functionality and will enhance maintainability.
1 parent e1e788f commit 679be52

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

clang/lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7950,21 +7950,8 @@ void Parser::ParseParameterDeclarationClause(
79507950
// Parse a C++23 Explicit Object Parameter
79517951
// We do that in all language modes to produce a better diagnostic.
79527952
SourceLocation ThisLoc;
7953-
if (getLangOpts().CPlusPlus && Tok.is(tok::kw_this)) {
7953+
if (getLangOpts().CPlusPlus && Tok.is(tok::kw_this))
79547954
ThisLoc = ConsumeToken();
7955-
// C++23 [dcl.fct]p6:
7956-
// An explicit-object-parameter-declaration is a parameter-declaration
7957-
// with a this specifier. An explicit-object-parameter-declaration
7958-
// shall appear only as the first parameter-declaration of a
7959-
// parameter-declaration-list of either:
7960-
// - a member-declarator that declares a member function, or
7961-
// - a lambda-declarator.
7962-
//
7963-
// The parameter-declaration-list of a requires-expression is not such
7964-
// a context.
7965-
if (DeclaratorCtx == DeclaratorContext::RequiresExpr)
7966-
Diag(ThisLoc, diag::err_requires_expr_explicit_object_parameter);
7967-
}
79687955

79697956
ParsedTemplateInfo TemplateInfo;
79707957
ParseDeclarationSpecifiers(DS, TemplateInfo, AS_none,

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9519,15 +9519,28 @@ Sema::ActOnStartRequiresExpr(SourceLocation RequiresKWLoc,
95199519
} else if (Param->getType().hasQualifiers()) {
95209520
Diag(Param->getBeginLoc(), diag::err_void_param_qualified);
95219521
}
9522-
}
9523-
9524-
if (Param->hasDefaultArg())
9522+
} else if (Param->hasDefaultArg()) {
95259523
// C++2a [expr.prim.req] p4
95269524
// [...] A local parameter of a requires-expression shall not have a
95279525
// default argument. [...]
95289526
Diag(Param->getDefaultArgRange().getBegin(),
95299527
diag::err_requires_expr_local_parameter_default_argument);
9530-
// Ignore default argument and move on
9528+
// Ignore default argument and move on
9529+
} else if (Param->isExplicitObjectParameter()) {
9530+
// C++23 [dcl.fct]p6:
9531+
// An explicit-object-parameter-declaration is a parameter-declaration
9532+
// with a this specifier. An explicit-object-parameter-declaration
9533+
// shall appear only as the first parameter-declaration of a
9534+
// parameter-declaration-list of either:
9535+
// - a member-declarator that declares a member function, or
9536+
// - a lambda-declarator.
9537+
//
9538+
// The parameter-declaration-list of a requires-expression is not such
9539+
// a context.
9540+
Diag(Param->getExplicitObjectParamThisLoc(),
9541+
diag::err_requires_expr_explicit_object_parameter);
9542+
Param->setExplicitObjectParameterLoc(SourceLocation());
9543+
}
95319544

95329545
Param->setDeclContext(Body);
95339546
// If this has an identifier, add it to the scope stack.

0 commit comments

Comments
 (0)