llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Oliver Hunt (ojhunt)

<details>
<summary>Changes</summary>

Make 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:

- (modified) clang/lib/Sema/SemaTemplate.cpp (+3-1) 
- (added) clang/test/SemaCXX/concept-diagnose-unexpanded-pack.cpp (+13) 


``````````diff
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); }

``````````

</details>


https://github.com/llvm/llvm-project/pull/147938
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to