-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[Clang] Mark a concept as being invalid if the constraint is invalid #147938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-clang Author: Oliver Hunt (ojhunt) ChangesMake sure to mark a concept decl as being invalid if the constraint is invalid. Full diff: https://github.com/llvm/llvm-project/pull/147938.diff 2 Files Affected:
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 1a98b3583185e..b76619fc50268 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -8968,8 +8968,10 @@ Sema::ActOnFinishConceptDefinition(Scope *S, ConceptDecl *C,
Expr *ConstraintExpr,
const ParsedAttributesView &Attrs) {
assert(!C->hasDefinition() && "Concept already defined");
- if (DiagnoseUnexpandedParameterPack(ConstraintExpr))
+ if (DiagnoseUnexpandedParameterPack(ConstraintExpr)) {
+ C->setInvalidDecl();
return nullptr;
+ }
C->setDefinition(ConstraintExpr);
ProcessDeclAttributeList(S, C, Attrs);
diff --git a/clang/test/SemaCXX/concept-diagnose-unexpanded-pack.cpp b/clang/test/SemaCXX/concept-diagnose-unexpanded-pack.cpp
new file mode 100644
index 0000000000000..549801f04dac3
--- /dev/null
+++ b/clang/test/SemaCXX/concept-diagnose-unexpanded-pack.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+
+template <typename T> void foo();
+template <class... Ts>
+concept ConceptA = requires { foo<Ts>(); };
+// expected-error@-1 {{expression contains unexpanded parameter pack 'Ts'}}
+
+template <class>
+concept ConceptB = ConceptA<int>;
+
+template <ConceptB Foo> void bar(Foo);
+
+void test() { bar(1); }
|
cor3ntin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
| // RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s | ||
|
|
||
| template <typename T> void foo(); | ||
| template <class... Ts> | ||
| concept ConceptA = requires { foo<Ts>(); }; | ||
| // expected-error@-1 {{expression contains unexpanded parameter pack 'Ts'}} | ||
|
|
||
| template <class> | ||
| concept ConceptB = ConceptA<int>; | ||
|
|
||
| template <ConceptB Foo> void bar(Foo); | ||
|
|
||
| void test() { bar(1); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can put that in an existing file, test/SemaCXX/concept-crash-on-diagnostic.cpp seems appropriate (in a GH138823 namespace)
8beb2ee to
5f8556c
Compare
shafik
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should have had a release note
Make sure to mark a concept decl as being invalid if the constraint is invalid.
Fixes #138823