Skip to content

Commit 03229e7

Browse files
authored
[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 #109780
1 parent 68a5f5d commit 03229e7

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

clang/lib/Parse/ParseTemplate.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,17 @@ Parser::ParseConceptDefinition(const ParsedTemplateInfo &TemplateInfo,
331331
if (!TryConsumeToken(tok::equal)) {
332332
Diag(Tok.getLocation(), diag::err_expected) << tok::equal;
333333
SkipUntil(tok::semi);
334+
if (D)
335+
D->setInvalidDecl();
334336
return nullptr;
335337
}
336338

337339
ExprResult ConstraintExprResult =
338340
Actions.CorrectDelayedTyposInExpr(ParseConstraintExpression());
339341
if (ConstraintExprResult.isInvalid()) {
340342
SkipUntil(tok::semi);
343+
if (D)
344+
D->setInvalidDecl();
341345
return nullptr;
342346
}
343347

clang/test/SemaTemplate/concepts.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,3 +1151,17 @@ int test() {
11511151
}
11521152

11531153
}
1154+
1155+
namespace GH109780 {
1156+
1157+
template <typename T>
1158+
concept Concept; // expected-error {{expected '='}}
1159+
1160+
bool val = Concept<int>;
1161+
1162+
template <typename T>
1163+
concept C = invalid; // expected-error {{use of undeclared identifier 'invalid'}}
1164+
1165+
bool val2 = C<int>;
1166+
1167+
} // namespace GH109780

0 commit comments

Comments
 (0)