aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/cp/decl.cc12
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/class-deduction-new1.C16
-rw-r--r--gcc/testsuite/g++.dg/cpp23/auto-array2.C11
3 files changed, 39 insertions, 0 deletions
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 6534a7f..10e6956 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -11087,6 +11087,18 @@ create_array_type_for_decl (tree name, tree type, tree size, location_t loc)
if (type == error_mark_node || size == error_mark_node)
return error_mark_node;
+ /* [dcl.type.class.deduct] prohibits forming an array of placeholder
+ for a deduced class type. */
+ if (is_auto (type) && CLASS_PLACEHOLDER_TEMPLATE (type))
+ {
+ if (name)
+ error_at (loc, "%qD declared as array of template placeholder "
+ "type %qT", name, type);
+ else
+ error ("creating array of template placeholder type %qT", type);
+ return error_mark_node;
+ }
+
/* If there are some types which cannot be array elements,
issue an error-message and return. */
switch (TREE_CODE (type))
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction-new1.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction-new1.C
new file mode 100644
index 0000000..7028335
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction-new1.C
@@ -0,0 +1,16 @@
+// PR c++/101988
+// { dg-do compile { target c++17 } }
+
+template<typename T>
+struct A {
+ A(T);
+ A();
+};
+auto p1 = new A[]{1}; // { dg-error "creating array of template placeholder type" }
+auto p2 = new A[1]{1}; // { dg-error "invalid use of placeholder" }
+auto p3 = new A<int>[]{1};
+auto p4 = new A<int>[1]{1};
+auto p5 = new A[]{1, 2}; // { dg-error "creating array of template placeholder type" }
+auto p6 = new A<int>[]{1, 2};
+auto p7 = new A<int>[]{A(1), A(1)};
+auto p8 = new A<int>[2]{A(1), A(1)};
diff --git a/gcc/testsuite/g++.dg/cpp23/auto-array2.C b/gcc/testsuite/g++.dg/cpp23/auto-array2.C
new file mode 100644
index 0000000..0643168
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp23/auto-array2.C
@@ -0,0 +1,11 @@
+// PR c++/101988
+// { dg-do compile { target c++17 } }
+
+template<class T> struct A { A(); };
+A<int> a[3];
+auto (*p)[3] = &a;
+A<int> (*p2)[3] = &a;
+A (*p3)[3] = &a; // { dg-error "template placeholder type" }
+auto (&r)[3] = a;
+A<int> (&r2)[3] = a;
+A (&r3)[3] = a; // { dg-error "template placeholder type" }