Skip to content

Commit

Permalink
[Clang][Parser] Don't evaluate concept when its definition is invalid (
Browse files Browse the repository at this point in the history
…llvm#111179)

Since llvm#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 llvm#109780
  • Loading branch information
zyn0217 authored Oct 10, 2024
1 parent 68a5f5d commit 03229e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clang/lib/Parse/ParseTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,17 @@ 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;
}

ExprResult ConstraintExprResult =
Actions.CorrectDelayedTyposInExpr(ParseConstraintExpression());
if (ConstraintExprResult.isInvalid()) {
SkipUntil(tok::semi);
if (D)
D->setInvalidDecl();
return nullptr;
}

Expand Down
14 changes: 14 additions & 0 deletions clang/test/SemaTemplate/concepts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 03229e7

Please sign in to comment.