]> gcc.gnu.org Git - gcc.git/commitdiff
c++: DEPENDENT_OPERATOR_TYPE as type of NTTP [PR104074]
authorPatrick Palka <ppalka@redhat.com>
Tue, 18 Jan 2022 19:50:06 +0000 (14:50 -0500)
committerPatrick Palka <ppalka@redhat.com>
Tue, 18 Jan 2022 19:50:06 +0000 (14:50 -0500)
We're incorrectly rejecting the below testcase during template argument
coercion because invalid_nontype_parm_type_p returns true for
DEPENDENT_OPERATOR_TYPE in C++17 mode.

This patch fixes this by partially rewriting invalid_nontype_parm_type_p
in terms of WILDCARD_TYPE_P, for which DEPENDENT_OPERATOR_TYPE is true,
so that the predicate handles wildcard types consistently.

PR c++/104074

gcc/cp/ChangeLog:

* pt.cc (invalid_nontype_parm_type_p): Use WILDCARD_TYPE_P so
that we return false for DEPENDENT_OPERATOR_TYPE too.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/nontype-auto20.C: New test.

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

index 4a2b33ec9403e255ba57ddd12d94118439b33103..586ad1c97f63454584fabf2284badd5b646e54f8 100644 (file)
@@ -26931,16 +26931,14 @@ invalid_nontype_parm_type_p (tree type, tsubst_flags_t complain)
        }
       return false;
     }
-  else if (TREE_CODE (type) == TYPENAME_TYPE)
-    return false;
-  else if (TREE_CODE (type) == DECLTYPE_TYPE)
-    return false;
   else if (TREE_CODE (type) == NULLPTR_TYPE)
     return false;
-  /* A bound template template parm could later be instantiated to have a valid
-     nontype parm type via an alias template.  */
-  else if (cxx_dialect >= cxx11
-          && TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM)
+  else if (TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM
+          && cxx_dialect < cxx11)
+    /* Fall through; before C++11 alias templates, a bound ttp
+       always instantiates into a class type.  */;
+  else if (WILDCARD_TYPE_P (type))
+    /* Any other wildcard type not already handled above is allowed.  */
     return false;
   else if (TREE_CODE (type) == COMPLEX_TYPE)
     /* Fall through.  */;
diff --git a/gcc/testsuite/g++.dg/cpp1z/nontype-auto20.C b/gcc/testsuite/g++.dg/cpp1z/nontype-auto20.C
new file mode 100644 (file)
index 0000000..87a2a5f
--- /dev/null
@@ -0,0 +1,5 @@
+// PR c++/104074
+// { dg-do compile { target c++17 } }
+
+template<auto> class gr_sp;
+template<class T> using gr_rp = gr_sp<T::value + 42>;
This page took 0.115014 seconds and 5 git commands to generate.