public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-1224] c++: top-level cv-quals on type of NTTP [PR100893]
@ 2021-06-04 18:10 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2021-06-04 18:10 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:6f8c9691495ad5a307db98dc19c3296ee4e6de64

commit r12-1224-g6f8c9691495ad5a307db98dc19c3296ee4e6de64
Author: Patrick Palka <ppalka@redhat.com>
Date:   Fri Jun 4 14:08:26 2021 -0400

    c++: top-level cv-quals on type of NTTP [PR100893]
    
    Here, we're rejecting the specialization of g<T,F> with T=A, F=&f in
    param4.C below due to a spurious constness mismatch between the type of
    the template argument &f and the substituted type of the parm F (the
    latter has a top-level const).  Note that this mismatch doesn't occur
    with object pointers because in that case a call to
    perform_qualification_conversions from convert_nontype_argument
    implicitly adds a top-level const to the argument (via a cast) to match.
    
    This however seems to be a manifestation of a more general conformance
    issue: we're not dropping top-level cv-quals on the substituted
    type of an NTTP as per [temp.param]/6 (we only do so at parse time in
    process_template_parm).  So this patch makes convert_template_argument
    drop top-level cv-quals accordingly.
    
            PR c++/100893
    
    gcc/cp/ChangeLog:
    
            * pt.c (convert_template_argument): Strip top-level cv-quals
            on the substituted type of a non-type template parameter.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/template/param4.C: New test.
            * g++.dg/template/param5.C: New test.
            * g++.dg/cpp1z/nontype-auto19.C: New test.
            * g++.dg/cpp2a/concepts-decltype.C: Don't expect that the
            deduced type of a decltype(auto) NTTP has top-level cv-quals.

Diff:
---
 gcc/cp/pt.c                                    |  4 ++++
 gcc/testsuite/g++.dg/cpp1z/nontype-auto19.C    |  8 ++++++++
 gcc/testsuite/g++.dg/cpp2a/concepts-decltype.C |  2 +-
 gcc/testsuite/g++.dg/template/param4.C         | 10 ++++++++++
 gcc/testsuite/g++.dg/template/param5.C         |  7 +++++++
 5 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 744461ed8cb..2ae886d3a39 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -8499,6 +8499,10 @@ convert_template_argument (tree parm,
       if (invalid_nontype_parm_type_p (t, complain))
 	return error_mark_node;
 
+      /* Drop top-level cv-qualifiers on the substituted/deduced type of
+	 this non-type template parameter, as per [temp.param]/6.  */
+      t = cv_unqualified (t);
+
       if (t != TREE_TYPE (parm))
 	t = canonicalize_type_argument (t, complain);
 
diff --git a/gcc/testsuite/g++.dg/cpp1z/nontype-auto19.C b/gcc/testsuite/g++.dg/cpp1z/nontype-auto19.C
new file mode 100644
index 00000000000..d6b904fd19c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/nontype-auto19.C
@@ -0,0 +1,8 @@
+// Verify top-level cv-qualifiers are dropped from the deduced
+// type of a non-type template parameter, as per [temp.param]/6.
+// { dg-do compile { target c++17 } }
+
+constexpr int x = 42;
+template<decltype(auto) V> decltype(V)& f();
+using type = decltype(f<x>());
+using type = int&;
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-decltype.C b/gcc/testsuite/g++.dg/cpp2a/concepts-decltype.C
index 13733c645f3..b375f74eb8a 100644
--- a/gcc/testsuite/g++.dg/cpp2a/concepts-decltype.C
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-decltype.C
@@ -61,7 +61,7 @@ constexpr int Z = 10;
 
 static_assert(deduced_as<0, int>);
 static_assert(deduced_as<0, int&>); // { dg-error "invalid variable template" }
-static_assert(deduced_as<Z, const int>);
+static_assert(deduced_as<Z, int>);
 static_assert(deduced_as<(Z), const int>); // { dg-error "invalid variable template" }
 static_assert(deduced_as<(Z), const int&>);
 
diff --git a/gcc/testsuite/g++.dg/template/param4.C b/gcc/testsuite/g++.dg/template/param4.C
new file mode 100644
index 00000000000..8061ff72ba2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/param4.C
@@ -0,0 +1,10 @@
+// PR c++/100893
+
+template<class T, typename T::type F> void g() { }
+
+struct A { typedef void (*const type)(); };
+void f();
+template void g<A, &f>();
+
+struct B { typedef void (B::*const type)(); void f(); };
+template void g<B, &B::f>();
diff --git a/gcc/testsuite/g++.dg/template/param5.C b/gcc/testsuite/g++.dg/template/param5.C
new file mode 100644
index 00000000000..89a5c04c09c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/param5.C
@@ -0,0 +1,7 @@
+// Verify top-level cv-qualifiers are dropped when determining the substituted
+// type of a non-type template parameter, as per [temp.param]/6.
+// { dg-do compile { target c++11 } }
+
+template<class T, T V> decltype(V)& f();
+using type = decltype(f<const volatile int, 0>());
+using type = int&;


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

only message in thread, other threads:[~2021-06-04 18:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-04 18:10 [gcc r12-1224] c++: top-level cv-quals on type of NTTP [PR100893] 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).