aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2025-04-04 14:03:58 -0400
committerPatrick Palka <ppalka@redhat.com>2025-04-04 14:03:58 -0400
commit6e973e87e3fec6f33e97edf8fce2fcd121e53961 (patch)
treea65abf9c77f3235b7be7fab7b45e6d99b8b55f00 /gcc
parentae4c22ab05501940e345ee799be3aa36ffa7269a (diff)
downloadgcc-6e973e87e3fec6f33e97edf8fce2fcd121e53961.zip
gcc-6e973e87e3fec6f33e97edf8fce2fcd121e53961.tar.gz
gcc-6e973e87e3fec6f33e97edf8fce2fcd121e53961.tar.bz2
c++: constraint variable used in evaluated context [PR117849]
Here we wrongly reject the type-requirement at parse time due to its use of the constraint variable 't' within a template argument (an evaluated context). Fix this simply by refining the "use of parameter outside function body" error path to exclude constraint variables. PR c++/104255 tracks the same issue for function parameters, but fixing that would be more involved, requiring changes to the PARM_DECL case of tsubst_expr. PR c++/117849 gcc/cp/ChangeLog: * semantics.cc (finish_id_expression_1): Allow use of constraint variable outside an unevaluated context. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-requires41.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/semantics.cc1
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/concepts-requires41.C25
2 files changed, 26 insertions, 0 deletions
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 7d8beb8..a10ef34 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -4755,6 +4755,7 @@ finish_id_expression_1 (tree id_expression,
body, except inside an unevaluated context (i.e. decltype). */
if (TREE_CODE (decl) == PARM_DECL
&& DECL_CONTEXT (decl) == NULL_TREE
+ && !CONSTRAINT_VAR_P (decl)
&& !cp_unevaluated_operand
&& !processing_contract_condition
&& !processing_omp_trait_property_expr)
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires41.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires41.C
new file mode 100644
index 0000000..28c9761
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires41.C
@@ -0,0 +1,25 @@
+// PR c++/117849
+// { dg-do compile { target c++20 } }
+
+template<int N>
+struct array {
+ constexpr int size() const { return N; }
+};
+
+struct vector {
+ int _size = 3;
+ constexpr int size() const { return _size; }
+};
+
+template<int N>
+struct integral_constant {
+ constexpr operator int() const { return N; }
+};
+
+template<class T>
+concept StaticSize = requires (T& t) {
+ typename integral_constant<t.size()>;
+};
+
+static_assert(StaticSize<array<5>>);
+static_assert(!StaticSize<vector>);