Debian Codegraph @

gcc/testsuite/g++.dg/cpp23/auto-array.C

raw
1 // PR c++/100975
2 // DR 2397 - auto specifier for pointers and references to arrays
3 // { dg-do compile { target c++11 } }
4
5 struct false_type { static constexpr bool value = false; };
6 struct true_type { static constexpr bool value = true; };
7 template<class T, class U>
8 struct is_same : false_type {};
9 template<class T>
10 struct is_same<T, T> : true_type {};
11
12 using U = int[3];
13
14 void
15 g ()
16 {
17 int a[3];
18 auto (*p)[3] = &a;
19 auto (&r)[3] = a;
20 int aa[3][3];
21 auto (*pp)[3][3] = &aa;
22 auto (&rr)[3][3] = aa;
23
24 auto (&&rv)[3] = U{};
25
26 static_assert (is_same<decltype (p), int(*)[3]>::value, "");
27 static_assert (is_same<decltype (pp), int(*)[3][3]>::value, "");
28 static_assert (is_same<decltype (r), int(&)[3]>::value, "");
29 static_assert (is_same<decltype (rv), int(&&)[3]>::value, "");
30 static_assert (is_same<decltype (rr), int(&)[3][3]>::value, "");
31
32 #if __cplusplus >= 201402L
33 // In a generic lambda parameter this was OK even before.
34 auto l = [](auto (&arr)[5]) { return arr[0]; };
35 #endif
36 }