aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2021-05-19 17:33:21 -0400
committerJason Merrill <jason@redhat.com>2021-05-19 23:10:53 -0400
commit75ab8b4829dec8c70470e8225c9add964f71ed74 (patch)
treec2ac53dfd730fda91342526f474a3243cd98a09f /gcc
parentfe9a6614a16b5ea7f12141c50b6b7de984390ed8 (diff)
downloadgcc-75ab8b4829dec8c70470e8225c9add964f71ed74.zip
gcc-75ab8b4829dec8c70470e8225c9add964f71ed74.tar.gz
gcc-75ab8b4829dec8c70470e8225c9add964f71ed74.tar.bz2
c++: _Complex template parameter [PR100634]
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/pt.c2
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/nontype-complex1.C8
2 files changed, 10 insertions, 0 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 32cd0b7..cbd2f3d 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -26563,6 +26563,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
index 0000000..4de2168
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/nontype-complex1.C
@@ -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>;