]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: ICE during requires-expr partial subst [PR118060]
authorPatrick Palka <ppalka@redhat.com>
Thu, 9 Jan 2025 15:50:19 +0000 (10:50 -0500)
committerPatrick Palka <ppalka@redhat.com>
Thu, 9 Jan 2025 15:50:19 +0000 (10:50 -0500)
Here during partial substitution of the requires-expression (as part of
CTAD constraint rewriting) we segfault from the INDIRECT_REF case of
convert_to_void due *f(u) being type-dependent.  We should just defer
checking convert_to_void until satisfaction.

PR c++/118060

gcc/cp/ChangeLog:

* constraint.cc (tsubst_valid_expression_requirement): Don't
check convert_to_void during partial substitution.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-requires40.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/constraint.cc
gcc/testsuite/g++.dg/cpp2a/concepts-requires40.C [new file with mode: 0644]

index 9bcb4dcc97942b5a164dd30ddd8717c078fb7f58..52ad88f37be0333be70e83055fd5d496092eea02 100644 (file)
@@ -1336,7 +1336,9 @@ tsubst_valid_expression_requirement (tree t, tree args, sat_info info)
 {
   tsubst_flags_t quiet = info.complain & ~tf_warning_or_error;
   tree r = tsubst_expr (t, args, quiet, info.in_decl);
-  if (convert_to_void (r, ICV_STATEMENT, quiet) != error_mark_node)
+  if (r != error_mark_node
+      && (processing_template_decl
+         || convert_to_void (r, ICV_STATEMENT, quiet) != error_mark_node))
     return r;
 
   if (info.diagnose_unsatisfaction_p ())
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires40.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires40.C
new file mode 100644 (file)
index 0000000..918bab4
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/118060
+// { dg-do compile { target c++20 } }
+
+int* f(int);
+
+template<class T>
+struct A {
+  template<class U> requires requires (U u) { *f(u); }
+  A(T, U);
+};
+
+A a{0, 0};