]> gcc.gnu.org Git - gcc.git/commitdiff
c++: deducing from class type of NTTP [PR105110]
authorPatrick Palka <ppalka@redhat.com>
Fri, 1 Apr 2022 18:56:20 +0000 (14:56 -0400)
committerPatrick Palka <ppalka@redhat.com>
Fri, 1 Apr 2022 18:56:20 +0000 (14:56 -0400)
Here when attempting to deduce T in the NTTP type A<T> from the argument
type 'const A<int>', we give up due to the const:

  types ‘A<T>’ and ‘const A<int>’ have incompatible cv-qualifiers

But since the type of an NTTP cannot be cv-qualified, it seems natural
to ignore cv-qualifiers on the argument type before attempting to unify
the two types.

PR c++/105110

gcc/cp/ChangeLog:

* pt.cc (unify) <case TEMPLATE_PARM_INDEX>: Drop cv-quals from
the argument type of an NTTP before deducing from it.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/nontype-class52.C: New test.

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

index bdba5cf3b850f75283bdded3573f05e639781058..75ed9a34018aa4f0914ec1d974d1f31f0eae8db5 100644 (file)
@@ -24266,8 +24266,9 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict,
              && !(strict & UNIFY_ALLOW_INTEGER)
              && TEMPLATE_PARM_LEVEL (parm) <= TMPL_ARGS_DEPTH (targs))
            {
-             /* Deduce it from the non-type argument.  */
-             tree atype = TREE_TYPE (arg);
+             /* Deduce it from the non-type argument.  As above, ignore
+                top-level quals here too.  */
+             tree atype = cv_unqualified (TREE_TYPE (arg));
              RECUR_AND_CHECK_FAILURE (tparms, targs,
                                       tparm, atype,
                                       UNIFY_ALLOW_NONE, explain_p);
diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class52.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class52.C
new file mode 100644 (file)
index 0000000..5616337
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/105110
+// { dg-do compile { target c++20 } }
+
+template<class> struct A { };
+
+template<auto> struct B { };
+
+template<class T, A<T> V> void f(B<V>);
+
+int main() {
+  constexpr A<int> a;
+  f(B<a>{});
+}
This page took 0.110445 seconds and 5 git commands to generate.