2009-12-16 04:14:24 +08:00
// RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic
2007-12-18 15:15:40 +08:00
int test1 ( ) {
typedef int x [ test1 ( ) ] ; // vla
2008-08-10 09:58:45 +08:00
static int y = sizeof ( x ) ; // expected-error {{not a compile-time constant}}
2007-12-18 15:15:40 +08:00
}
2008-05-21 13:06:46 +08:00
// PR2347
void f ( unsigned int m )
{
2008-05-21 13:37:55 +08:00
int e [ 2 ] [ m ] ;
2008-05-21 13:06:46 +08:00
e [ 0 ] [ 0 ] = 0 ;
}
2008-11-13 05:25:45 +08:00
// PR3048
2008-11-24 09:28:17 +08:00
int x = sizeof ( struct { char qq [ x ] ; } ) ; // expected-error {{fields must have a constant size}}
2008-11-13 05:25:45 +08:00
2008-12-07 08:20:55 +08:00
// PR2352
void f2 ( unsigned int m )
{
2014-03-08 06:36:23 +08:00
extern int e1 [ 2 ] [ m ] ; // expected-error {{variable length array declaration cannot have 'extern' linkage}}
2008-12-07 08:20:55 +08:00
2009-02-25 03:23:27 +08:00
e1 [ 0 ] [ 0 ] = 0 ;
2008-12-07 08:20:55 +08:00
}
// PR2361
int i ;
2008-12-07 08:59:53 +08:00
int c [ ] [ i ] ; // expected-error {{variably modified type declaration not allowed at file scope}}
int d [ i ] ; // expected-error {{variable length array declaration not allowed at file scope}}
2008-12-07 08:20:55 +08:00
2008-12-07 08:59:53 +08:00
int ( * e ) [ i ] ; // expected-error {{variably modified type declaration not allowed at file scope}}
2008-12-07 08:20:55 +08:00
void f3 ( )
{
2014-03-08 06:36:23 +08:00
static int a [ i ] ; // expected-error {{variable length array declaration cannot have 'static' storage duration}}
extern int b [ i ] ; // expected-error {{variable length array declaration cannot have 'extern' linkage}}
2008-12-07 08:20:55 +08:00
2014-03-08 06:36:23 +08:00
extern int ( * c1 ) [ i ] ; // expected-error {{variably modified type declaration cannot have 'extern' linkage}}
2008-12-07 08:20:55 +08:00
static int ( * d ) [ i ] ;
}
2009-02-26 11:58:54 +08:00
// PR3663
2011-06-14 14:38:10 +08:00
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}}
2009-04-27 05:57:51 +08:00
int a [ * ] ; // expected-error {{star modifier used outside of function prototype}}
int f4 ( int a [ * ] [ * ] ) ;
2009-05-16 20:15:55 +08:00
// PR2044
int pr2044 ( int b ) { int ( * c ( void ) ) [ b ] ; * * c ( ) = 2 ; } // expected-error {{variably modified type}}
int pr2044b ;
int ( * pr2044c ( void ) ) [ pr2044b ] ; // expected-error {{variably modified type}}
2009-05-30 00:34:15 +08:00
const int f5_ci = 1 ;
2020-10-16 10:32:15 +08:00
void f5 ( ) { char a [ ] [ f5_ci ] = { " " } ; } // expected-error {{variable-sized object may not be initialized}}
2010-02-01 13:02:49 +08:00
// PR5185
void pr5185 ( int a [ * ] ) ;
void pr5185 ( int a [ * ] ) / / expected - error { { variable length array must be bound in function definition } }
{
}
2012-02-07 07:29:57 +08:00
2015-04-08 06:08:51 +08:00
void pr23151 ( int ( * p1 ) [ * ] ) / / expected - error { { variable length array must be bound in function definition } }
{ }
2012-02-07 07:29:57 +08:00
// Make sure this isn't treated as an error
int TransformBug ( int a ) {
return sizeof ( * ( int ( * ) [ ( { goto v ; v : a ; } ) ] ) 0 ) ; // expected-warning {{use of GNU statement expression extension}}
}
2018-02-24 08:00:58 +08:00
// PR36157
struct {
int a [ // expected-error {{variable length array in struct}}
implicitly_declared ( ) // expected-warning {{implicit declaration}}
] ;
} ;
int ( * use_implicitly_declared ) ( ) = implicitly_declared ; // ok, was implicitly declared at file scope
2018-06-05 17:18:26 +08:00
void VLAPtrAssign ( int size ) {
int array [ 1 ] [ 2 ] [ 3 ] [ size ] [ 4 ] [ 5 ] ;
// This is well formed
int ( * p ) [ 2 ] [ 3 ] [ size ] [ 4 ] [ 5 ] = array ;
// Last array dimension too large
int ( * p2 ) [ 2 ] [ 3 ] [ size ] [ 4 ] [ 6 ] = array ; // expected-warning {{incompatible pointer types}}
// Second array dimension too large
int ( * p3 ) [ 20 ] [ 3 ] [ size ] [ 4 ] [ 5 ] = array ; // expected-warning {{incompatible pointer types}}
// Not illegal in C, program _might_ be well formed if size == 3.
int ( * p4 ) [ 2 ] [ size ] [ 3 ] [ 4 ] [ 5 ] = array ;
}
2020-10-16 10:32:15 +08:00
void pr44406 ( ) {
goto L ; // expected-error {{cannot jump}}
int z [ ( int ) ( 1.0 * 2 ) ] ; // expected-note {{bypasses initialization of variable length array}}
L : ;
}
const int pr44406_a = 32 ;
typedef struct {
char c [ pr44406_a ] ; // expected-warning {{folded to constant array as an extension}}
} pr44406_s ;
2020-12-03 23:01:53 +08:00
void test_fold_to_constant_array ( ) {
const int ksize = 4 ;
goto jump_over_a1 ; // expected-error{{cannot jump from this goto statement to its label}}
char a1 [ ksize ] ; // expected-note{{variable length array}}
jump_over_a1 : ;
goto jump_over_a2 ;
char a2 [ ksize ] = " foo " ; // expected-warning{{variable length array folded to constant array as an extension}}
jump_over_a2 : ;
goto jump_over_a3 ;
char a3 [ ksize ] = { } ; // expected-warning {{variable length array folded to constant array as an extension}} expected-warning{{use of GNU empty initializer}}
jump_over_a3 : ;
goto jump_over_a4 ; // expected-error{{cannot jump from this goto statement to its label}}
char a4 [ ksize ] [ 2 ] ; // expected-note{{variable length array}}
jump_over_a4 : ;
char a5 [ ksize ] [ 2 ] = { } ; // expected-warning {{variable length array folded to constant array as an extension}} expected-warning{{use of GNU empty initializer}}
int a6 [ ksize ] = { 1 , 2 , 3 , 4 } ; // expected-warning{{variable length array folded to constant array as an extension}}
// expected-warning@+1{{variable length array folded to constant array as an extension}}
int a7 [ ksize ] __attribute__ ( ( annotate ( " foo " ) ) ) = { 1 , 2 , 3 , 4 } ;
// expected-warning@+1{{variable length array folded to constant array as an extension}}
char a8 [ 2 ] [ ksize ] = { { 1 , 2 , 3 , 4 } , { 4 , 3 , 2 , 1 } } ;
2021-03-11 02:51:00 +08:00
// expected-warning@+1{{variable length array folded to constant array as an extension}}
char ( * a9 ) [ ] = ( char [ 2 ] [ ksize ] ) { { 1 , 2 , 3 , 4 } , { 4 , 3 , 2 , 1 } } ;
char ( * a10 ) [ ksize ] = 0 ;
2020-12-03 23:01:53 +08:00
}