1 // RUN: %clang_cc1 -std=c++1y %s -verify -triple=x86_64-linux-gnu -pedantic-errors
2
3 // FIXME: many diagnostics here say 'variably modified type'.
4 // catch this case and say 'array of runtime bound' instead.
5
6 namespace std { struct type_info; }
7
8 struct S {
9 int arr[__SIZE_MAX__ / 32];
10 };
11 S s[32]; // expected-error {{array is too large}}
12
13 int n;
14 int a[n]; // expected-error {{not allowed at file scope}}
15
16 struct T {
17 int a[n]; // expected-error {{fields must have a constant size}}
18 static int b[n]; // expected-error {{not allowed at file scope}}
19 };
20
21 int g(int n, int a[n]);
22
23 template<typename T> struct X {};
24 template<int N, int[N]> struct Y {};
25 template<int[n]> struct Z {}; // expected-error {{of variably modified type}}
26
f(int n)27 int f(int n) {
28 int arb[n]; // expected-note 3{{here}}
29 [arb] {} (); // expected-error {{cannot be captured}}
30
31 // FIXME: an array of runtime bound can be captured by reference.
32 [&arb] { // expected-error {{cannot be captured}}
33 // Capturing the array implicitly captures the bound, if we need it
34 // in a range-based for loop.
35 for (auto &n : arb) { } // expected-error {{cannot be captured}}
36 } ();
37
38 X<int[n]> x; // expected-error {{variably modified type}}
39
40 int arb_neg[-1]; // expected-error {{negative size}}
41 int arb_of_array[n][2];
42 int arr[3] = { 1, 2, 3, 4 }; // expected-error {{excess elements}}
43 char foo[4] = "fool"; // expected-error {{initializer-string for char array is too long}}
44
45 static int not_auto1[n]; // expected-error {{can not have 'static'}}
46 extern int not_auto2[n]; // expected-error {{can not have 'extern'}}
47 // FIXME: say 'thread_local' not 'static'.
48 thread_local int not_auto1[n]; // expected-error {{can not have 'static'}}
49
50 // FIXME: these should all be invalid.
51 auto &&ti1 = typeid(arb);
52 auto &&ti2 = typeid(int[n]);
53 auto &&so1 = sizeof(arb);
54 auto &&so2 = sizeof(int[n]);
55 auto *p = &arb;
56 decltype(arb) arb2;
57 int (*arbp)[n] = 0;
58 const int (&arbr)[n] = arbr; // expected-warning {{not yet bound}}
59 typedef int arbty[n];
60 int array_of_arb[2][n];
61
62 struct Dyn { Dyn() {} Dyn(int) {} ~Dyn() {} };
63
64 // FIXME: these should be valid.
65 int arb_dynamic[n] = { 1, 2, 3, 4 }; // expected-error {{may not be initialized}}
66 Dyn dyn[n]; // expected-error {{non-POD}}
67 Dyn dyn_init[n] = { 1, 2, 3, 4 }; // expected-error {{non-POD}}
68 }
69