]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: concepts and conversions [PR112632]
authorJason Merrill <jason@redhat.com>
Tue, 23 Sep 2025 10:19:49 +0000 (11:19 +0100)
committerJason Merrill <jason@redhat.com>
Sat, 27 Sep 2025 08:06:34 +0000 (09:06 +0100)
One case missed in my fix for this PR: Here we were omitting the
IMPLICIT_CONV_EXPR that expresses the conversion from int to char because
the target type was non-dependent and the argument was not type-dependent.
But we still need it if the argument is value-dependent.

PR c++/112632

gcc/cp/ChangeLog:

* pt.cc (convert_template_argument): Also force IMPLICIT_CONV_EXPR
if the argument is value-dependent.

gcc/testsuite/ChangeLog:

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

gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp2a/concepts-conv4.C [new file with mode: 0644]

index 96ead4f1b554ff1df3d11d58353f62eb58d25633..bd60d515653b483a8cf06759f1be53a4ac67161e 100644 (file)
@@ -8927,8 +8927,9 @@ convert_template_argument (tree parm,
          && same_type_p (TREE_TYPE (orig_arg), t))
        orig_arg = TREE_OPERAND (orig_arg, 0);
 
-      if (!type_dependent_expression_p (orig_arg)
-         && !uses_template_parms (t))
+      if (!uses_template_parms (t)
+         && !(force_conv ? uses_template_parms (orig_arg)
+              : type_dependent_expression_p (orig_arg)))
        /* We used to call digest_init here.  However, digest_init
           will report errors, which we don't want when complain
           is zero.  More importantly, digest_init will try too
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-conv4.C b/gcc/testsuite/g++.dg/cpp2a/concepts-conv4.C
new file mode 100644 (file)
index 0000000..107a1bb
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/112632
+// { dg-do compile { target c++20 } }
+
+template<int N> concept A = N != 0;
+template<char C> concept B = A<C>;
+template<int N> concept C = B<N>;
+
+static_assert(A<256>);
+static_assert(!C<256>);