| 1 |
// RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic |
| 2 |
|
| 3 |
int test1(void) { |
| 4 |
typedef int x[test1()]; // vla |
| 5 |
static int y = sizeof(x); // expected-error {{not a compile-time constant}} |
| 6 |
} |
| 7 |
|
| 8 |
// PR2347 |
| 9 |
void f (unsigned int m) |
| 10 |
{ |
| 11 |
int e[2][m]; |
| 12 |
|
| 13 |
e[0][0] = 0; |
| 14 |
} |
| 15 |
|
| 16 |
// PR3048 |
| 17 |
int x = sizeof(struct{char qq[x];}); // expected-error {{fields must have a constant size}} |
| 18 |
|
| 19 |
// PR2352 |
| 20 |
void f2(unsigned int m) |
| 21 |
{ |
| 22 |
extern int e1[2][m]; // expected-error {{variable length array declaration cannot have 'extern' linkage}} |
| 23 |
|
| 24 |
e1[0][0] = 0; |
| 25 |
|
| 26 |
} |
| 27 |
|
| 28 |
// PR2361 |
| 29 |
int i; |
| 30 |
int c[][i]; // expected-error {{variably modified type declaration not allowed at file scope}} |
| 31 |
int d[i]; // expected-error {{variable length array declaration not allowed at file scope}} |
| 32 |
|
| 33 |
int (*e)[i]; // expected-error {{variably modified type declaration not allowed at file scope}} |
| 34 |
|
| 35 |
void f3(void) |
| 36 |
{ |
| 37 |
static int a[i]; // expected-error {{variable length array declaration cannot have 'static' storage duration}} |
| 38 |
extern int b[i]; // expected-error {{variable length array declaration cannot have 'extern' linkage}} |
| 39 |
|
| 40 |
extern int (*c1)[i]; // expected-error {{variably modified type declaration cannot have 'extern' linkage}} |
| 41 |
static int (*d)[i]; |
| 42 |
} |
| 43 |
|
| 44 |
// PR3663 |
| 45 |
static const unsigned array[((2 * (int)((((4) / 2) + 1.0/3.0) * (4) - 1e-8)) + 1)]; // expected-warning {{variable length array folded to constant array as an extension}} |
| 46 |
|
| 47 |
int a[*]; // expected-error {{star modifier used outside of function prototype}} |
| 48 |
int f4(int a[*][*]); |
| 49 |
|
| 50 |
// PR2044 |
| 51 |
int pr2044(int b) {int (*c(void))[b];**c() = 2;} // expected-error {{variably modified type}} |
| 52 |
int pr2044b; |
| 53 |
int (*pr2044c(void))[pr2044b]; // expected-error {{variably modified type}} |
| 54 |
|
| 55 |
const int f5_ci = 1; |
| 56 |
void f5(void) { char a[][f5_ci] = {""}; } // expected-error {{variable-sized object may not be initialized}} |
| 57 |
|
| 58 |
// PR5185 |
| 59 |
void pr5185(int a[*]); |
| 60 |
void pr5185(int a[*]) // expected-error {{variable length array must be bound in function definition}} |
| 61 |
{ |
| 62 |
} |
| 63 |
|
| 64 |
void pr23151(int (*p1)[*]) // expected-error {{variable length array must be bound in function definition}} |
| 65 |
{} |
| 66 |
|
| 67 |
// Make sure this isn't treated as an error |
| 68 |
int TransformBug(int a) { |
| 69 |
return sizeof(*(int(*)[({ goto v; v: a;})]) 0); // expected-warning {{use of GNU statement expression extension}} |
| 70 |
} |
| 71 |
|
| 72 |
// PR36157 |
| 73 |
struct { |
| 74 |
int a[ // expected-error {{variable length array in struct}} |
| 75 |
implicitly_declared() // expected-error {{call to undeclared function 'implicitly_declared'; ISO C99 and later do not support implicit function declarations}} |
| 76 |
]; |
| 77 |
}; |
| 78 |
int (*use_implicitly_declared)(void) = implicitly_declared; // ok, was implicitly declared at file scope |
| 79 |
|
| 80 |
void VLAPtrAssign(int size) { |
| 81 |
int array[1][2][3][size][4][5]; |
| 82 |
// This is well formed |
| 83 |
int (*p)[2][3][size][4][5] = array; |
| 84 |
// Last array dimension too large |
| 85 |
int (*p2)[2][3][size][4][6] = array; // expected-error {{incompatible pointer types}} |
| 86 |
// Second array dimension too large |
| 87 |
int (*p3)[20][3][size][4][5] = array; // expected-error {{incompatible pointer types}} |
| 88 |
|
| 89 |
// Not illegal in C, program _might_ be well formed if size == 3. |
| 90 |
int (*p4)[2][size][3][4][5] = array; |
| 91 |
} |
| 92 |
|
| 93 |
void pr44406(void) { |
| 94 |
goto L; // expected-error {{cannot jump}} |
| 95 |
int z[(int)(1.0 * 2)]; // expected-note {{bypasses initialization of variable length array}} |
| 96 |
L:; |
| 97 |
} |
| 98 |
|
| 99 |
const int pr44406_a = 32; |
| 100 |
typedef struct { |
| 101 |
char c[pr44406_a]; // expected-warning {{folded to constant array as an extension}} |
| 102 |
} pr44406_s; |
| 103 |
|
| 104 |
void test_fold_to_constant_array(void) { |
| 105 |
const int ksize = 4; |
| 106 |
|
| 107 |
goto jump_over_a1; // expected-error{{cannot jump from this goto statement to its label}} |
| 108 |
char a1[ksize]; // expected-note{{variable length array}} |
| 109 |
jump_over_a1:; |
| 110 |
|
| 111 |
goto jump_over_a2; |
| 112 |
char a2[ksize] = "foo"; // expected-warning{{variable length array folded to constant array as an extension}} |
| 113 |
jump_over_a2:; |
| 114 |
|
| 115 |
goto jump_over_a3; |
| 116 |
char a3[ksize] = {}; // expected-warning {{variable length array folded to constant array as an extension}} expected-warning{{use of an empty initializer is a C23 extension}} |
| 117 |
jump_over_a3:; |
| 118 |
|
| 119 |
goto jump_over_a4; // expected-error{{cannot jump from this goto statement to its label}} |
| 120 |
char a4[ksize][2]; // expected-note{{variable length array}} |
| 121 |
jump_over_a4:; |
| 122 |
|
| 123 |
char a5[ksize][2] = {}; // expected-warning {{variable length array folded to constant array as an extension}} expected-warning{{use of an empty initializer is a C23 extension}} |
| 124 |
|
| 125 |
int a6[ksize] = {1,2,3,4}; // expected-warning{{variable length array folded to constant array as an extension}} |
| 126 |
|
| 127 |
// expected-warning@+1{{variable length array folded to constant array as an extension}} |
| 128 |
int a7[ksize] __attribute__((annotate("foo"))) = {1,2,3,4}; |
| 129 |
|
| 130 |
// expected-warning@+1{{variable length array folded to constant array as an extension}} |
| 131 |
char a8[2][ksize] = {{1,2,3,4},{4,3,2,1}}; |
| 132 |
|
| 133 |
// expected-warning@+1{{variable length array folded to constant array as an extension}} |
| 134 |
char (*a9)[] = (char[2][ksize]) {{1,2,3,4},{4,3,2,1}}; |
| 135 |
|
| 136 |
char (*a10)[ksize] = 0; |
| 137 |
} |