[Clang][Parser] Don't evaluate concept when its definition is invalid (#111179)

Since #103867, the nullness of the concept declaration has been turned
to represent a state in which the concept definition is being parsed and
used for self-reference checking.

However, PR missed a case where such a definition could be invalid, and
we shall inhibit making it into evaluation.

Fixes https://github.com/llvm/llvm-project/issues/109780
This commit is contained in:
Younan Zhang
2024-10-10 09:36:00 +08:00
committed by GitHub
parent 68a5f5db7c
commit 03229e7c0b
2 changed files with 18 additions and 0 deletions

View File

@@ -331,6 +331,8 @@ Parser::ParseConceptDefinition(const ParsedTemplateInfo &TemplateInfo,
if (!TryConsumeToken(tok::equal)) {
Diag(Tok.getLocation(), diag::err_expected) << tok::equal;
SkipUntil(tok::semi);
if (D)
D->setInvalidDecl();
return nullptr;
}
@@ -338,6 +340,8 @@ Parser::ParseConceptDefinition(const ParsedTemplateInfo &TemplateInfo,
Actions.CorrectDelayedTyposInExpr(ParseConstraintExpression());
if (ConstraintExprResult.isInvalid()) {
SkipUntil(tok::semi);
if (D)
D->setInvalidDecl();
return nullptr;
}

View File

@@ -1151,3 +1151,17 @@ int test() {
}
}
namespace GH109780 {
template <typename T>
concept Concept; // expected-error {{expected '='}}
bool val = Concept<int>;
template <typename T>
concept C = invalid; // expected-error {{use of undeclared identifier 'invalid'}}
bool val2 = C<int>;
} // namespace GH109780