invalid_tparm_referent_p was rejecting using the address of a class NTTP
object as a template argument, but this should be fine.
PR c++/113242
PR c++/99493
gcc/cp/ChangeLog:
* pt.cc (invalid_tparm_referent_p) <case ADDR_EXPR>: Suppress
DECL_ARTIFICIAL rejection test for class NTTP objects.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/nontype-class61.C: New test.
* g++.dg/cpp2a/nontype-class62.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
* a string literal (5.13.5),
* the result of a typeid expression (8.2.8), or
* a predefined __func__ variable (11.4.1). */
- else if (VAR_P (decl) && DECL_ARTIFICIAL (decl))
+ else if (VAR_P (decl) && DECL_ARTIFICIAL (decl)
+ && !DECL_NTTP_OBJECT_P (decl))
{
+ gcc_checking_assert (DECL_TINFO_P (decl) || DECL_FNAME_P (decl));
if (complain & tf_error)
error ("the address of %qD is not a valid template argument",
decl);
--- /dev/null
+// PR c++/113242
+// { dg-do compile { target c++20 } }
+
+struct wrapper { int n; };
+
+template<const wrapper& X>
+void f1() {
+ static_assert(X.n == 42);
+}
+
+template<const wrapper* X>
+void f2() {
+ static_assert(X->n == 42);
+}
+
+template<wrapper X>
+void g() {
+ f1<X>();
+ f2<&X>();
+}
+
+int main() {
+ constexpr wrapper X = {42};
+ g<X>();
+}
--- /dev/null
+// PR c++/99493
+// { dg-do compile { target c++20 } }
+
+struct owner{int m;};
+struct view{const int*m;constexpr view(const owner&o):m{&o.m}{}};
+template<view V>struct constant{};
+template<owner O>constexpr constant<O>v{};
+constexpr auto a=v<owner{}>;