[clang] [clang] Fixes #138823 (PR #147938)
Oliver Hunt via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 10 04:11:41 PDT 2025
https://github.com/ojhunt created https://github.com/llvm/llvm-project/pull/147938
Make sure to mark a concept decl as being invalid if the constraint is invalid.
>From 8beb2eeab5270df51408d233d90d89be735b1828 Mon Sep 17 00:00:00 2001
From: Oliver Hunt <oliver at apple.com>
Date: Thu, 10 Jul 2025 03:57:32 -0700
Subject: [PATCH] [clang] Fixes #138823
Make sure to mark a concept decl as being invalid if the constraint is
invalid.
---
clang/lib/Sema/SemaTemplate.cpp | 4 +++-
.../SemaCXX/concept-diagnose-unexpanded-pack.cpp | 13 +++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
create mode 100644 clang/test/SemaCXX/concept-diagnose-unexpanded-pack.cpp
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 at -1 {{expression contains unexpanded parameter pack 'Ts'}}
+
+template <class>
+concept ConceptB = ConceptA<int>;
+
+template <ConceptB Foo> void bar(Foo);
+
+void test() { bar(1); }
More information about the cfe-commits
mailing list