]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: _Complex template parameter [PR100634]
authorJason Merrill <jason@redhat.com>
Wed, 19 May 2021 21:33:21 +0000 (17:33 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 20 May 2021 03:12:28 +0000 (23:12 -0400)
We were crashing because invalid_nontype_parm_type_p allowed _Complex
template parms, but convert_nontype_argument didn't know what to do for
them.  Let's just disallow it, people can and should use std::complex
instead.

PR c++/100634

gcc/cp/ChangeLog:

* pt.c (invalid_nontype_parm_type_p): Return true for COMPLEX_TYPE.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/nontype-complex1.C: New test.

gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp2a/nontype-complex1.C [new file with mode: 0644]

index d30876ced9c593f7646c5be6360cfe8ced4c9f4d..1434beb80f4babd0b38c9d54a73aa1339ec0f9b5 100644 (file)
@@ -26620,6 +26620,8 @@ invalid_nontype_parm_type_p (tree type, tsubst_flags_t complain)
   else if (cxx_dialect >= cxx11
           && TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM)
     return false;
+  else if (TREE_CODE (type) == COMPLEX_TYPE)
+    /* Fall through.  */;
   else if (VOID_TYPE_P (type))
     /* Fall through.  */;
   else if (cxx_dialect >= cxx20)
diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-complex1.C b/gcc/testsuite/g++.dg/cpp2a/nontype-complex1.C
new file mode 100644 (file)
index 0000000..4de2168
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/100634
+// { dg-do compile { target c++20 } }
+// { dg-options "" }
+
+// We could support _Complex template arguments, but better I think to make
+// people use a standard type instead.
+template<_Complex int> struct ComplexInt {}; // { dg-error "not a valid type" }
+using CI = ComplexInt<1 + 3i>;