public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-7966] c++: deducing from class type of NTTP [PR105110]
@ 2022-04-01 18:57 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2022-04-01 18:57 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:95533fe4f014c10dd18de649927668aba6117daf

commit r12-7966-g95533fe4f014c10dd18de649927668aba6117daf
Author: Patrick Palka <ppalka@redhat.com>
Date:   Fri Apr 1 14:56:20 2022 -0400

    c++: deducing from class type of NTTP [PR105110]
    
    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.

Diff:
---
 gcc/cp/pt.cc                                 |  5 +++--
 gcc/testsuite/g++.dg/cpp2a/nontype-class52.C | 13 +++++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index bdba5cf3b85..75ed9a34018 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -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
index 00000000000..56163376afb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class52.C
@@ -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>{});
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-01 18:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-01 18:57 [gcc r12-7966] c++: deducing from class type of NTTP [PR105110] Patrick Palka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).