Author: Younan Zhang Date: 2024-10-10T09:36:00+08:00 New Revision: 03229e7c0b1f28b01a75d2d258b16b37c2d2e9b9
URL: https://github.com/llvm/llvm-project/commit/03229e7c0b1f28b01a75d2d258b16b37c2d2e9b9 DIFF: https://github.com/llvm/llvm-project/commit/03229e7c0b1f28b01a75d2d258b16b37c2d2e9b9.diff LOG: [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 Added: Modified: clang/lib/Parse/ParseTemplate.cpp clang/test/SemaTemplate/concepts.cpp Removed: ################################################################################ diff --git a/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp index de29652abbfd95..0953cfc3c017ef 100644 --- a/clang/lib/Parse/ParseTemplate.cpp +++ b/clang/lib/Parse/ParseTemplate.cpp @@ -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; } diff --git a/clang/test/SemaTemplate/concepts.cpp b/clang/test/SemaTemplate/concepts.cpp index a98ca3939222bd..312469313fc535 100644 --- a/clang/test/SemaTemplate/concepts.cpp +++ b/clang/test/SemaTemplate/concepts.cpp @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits