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);
--- /dev/null
+// 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&;
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&>);
--- /dev/null
+// 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>();
--- /dev/null
+// 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&;