if (type == error_mark_node || size == error_mark_node)
return error_mark_node;
- /* 8.3.4/1: If the type of the identifier of D contains the auto
- type-specifier, the program is ill-formed. */
- if (type_uses_auto (type))
- {
- if (name)
- error_at (loc, "%qD declared as array of %qT", name, type);
- else
- error ("creating array of %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))
// PR c++/48599
// { dg-do compile { target c++11 } }
+// Allowed since DR2397.
int v[1];
-auto (*p)[1] = &v; // { dg-error "8:.p. declared as array of .auto" }
+auto (*p)[1] = &v;
// deduction, the program is ill-formed.
auto i = 42, j = 42.0; // { dg-error "auto" }
-// New CWG issue
-auto a[2] = { 1, 2 }; // { dg-error "6:.a. declared as array of .auto" }
+// CWG issue 2397: [dcl.type.auto.deduct]/2: "T shall not be an array type".
+auto a[2] = { 1, 2 }; // { dg-error "20:unable to deduce" }
template<class T>
struct A { };
void foo(int i)
{
- auto x[1] = { 0 }; // { dg-error "8:.x. declared as array of .auto" }
+ auto x[1] = { 0 }; // { dg-error "19:unable to deduce" }
}
#include <initializer_list>
-auto foo[] = {}; // { dg-error "6:.foo. declared as array of .auto" }
+auto foo[] = {}; // { dg-error "15:unable to deduce" }
#include <initializer_list>
-auto x[2] = {}; // { dg-error "6:.x. declared as array of .auto" }
+auto x[2] = {}; // { dg-error "14:unable to deduce" }
--- /dev/null
+// PR c++/100975
+// DR 2397 - auto specifier for pointers and references to arrays
+// { dg-do compile { target c++11 } }
+
+struct false_type { static constexpr bool value = false; };
+struct true_type { static constexpr bool value = true; };
+template<class T, class U>
+struct is_same : false_type {};
+template<class T>
+struct is_same<T, T> : true_type {};
+
+using U = int[3];
+
+void
+g ()
+{
+ int a[3];
+ auto (*p)[3] = &a;
+ auto (&r)[3] = a;
+ int aa[3][3];
+ auto (*pp)[3][3] = &aa;
+ auto (&rr)[3][3] = aa;
+
+ auto (&&rv)[3] = U{};
+
+ static_assert (is_same<decltype (p), int(*)[3]>::value, "");
+ static_assert (is_same<decltype (pp), int(*)[3][3]>::value, "");
+ static_assert (is_same<decltype (r), int(&)[3]>::value, "");
+ static_assert (is_same<decltype (rv), int(&&)[3]>::value, "");
+ static_assert (is_same<decltype (rr), int(&)[3][3]>::value, "");
+
+#if __cplusplus >= 201402L
+ // In a generic lambda parameter this was OK even before.
+ auto l = [](auto (&arr)[5]) { return arr[0]; };
+#endif
+}
// PR c++/86915
// { dg-do compile { target c++17 } }
+// Allowed since DR2397.
-template<auto [1]> struct S; // { dg-error "creating array of .auto." }
+template<auto [1]> struct S;