2009-12-16 04:14:24 +08:00
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
2007-12-05 12:00:10 +08:00
struct foo { int a , b ; } ;
2008-07-08 00:46:50 +08:00
static struct foo t = ( struct foo ) { 0 , 0 } ;
2010-09-27 15:13:32 +08:00
static struct foo t1 = __builtin_choose_expr ( 0 , ( struct foo ) { 0 , 0 } , ( struct foo ) { 0 , 0 } ) ;
static struct foo t2 = { 0 , 0 } ;
2008-08-10 09:58:45 +08:00
static struct foo t3 = t2 ; // -expected-error {{initializer element is not a compile-time constant}}
2010-09-27 15:13:32 +08:00
static int * p = ( int [ ] ) { 2 , 4 } ;
2009-05-16 19:45:48 +08:00
static int x = ( int ) { 1 } ;
2008-01-09 08:05:37 +08:00
2008-08-10 09:58:45 +08:00
static int * p2 = ( int [ ] ) { 2 , x } ; // -expected-error {{initializer element is not a compile-time constant}}
2010-04-10 01:53:29 +08:00
static long * p3 = ( long [ ] ) { 2 , " x " } ; // -expected-warning {{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char [2]'}}
2008-01-10 04:58:06 +08:00
2010-07-29 22:29:34 +08:00
typedef struct { } cache_t ; // -expected-warning{{empty struct (accepted as an extension) has size 0 in C, size 1 in C++}}
2008-07-08 00:46:50 +08:00
static cache_t clo_I1_cache = ( ( cache_t ) { } ) ; // -expected-warning{{use of GNU empty initializer extension}}
2008-01-15 02:19:28 +08:00
typedef struct Test { int a ; int b ; } Test ;
static Test * ll = & ( Test ) { 0 , 0 } ;
2007-12-05 12:00:10 +08:00
extern void fooFunc ( struct foo * pfoo ) ;
int main ( int argc , char * * argv ) {
2008-01-10 04:58:06 +08:00
int * l = ( int [ ] ) { x , * p , * p2 } ;
2007-12-05 12:00:10 +08:00
fooFunc ( & ( struct foo ) { 1 , 2 } ) ;
}
2009-01-20 03:26:10 +08:00
struct Incomplete ; // expected-note{{forward declaration of 'struct Incomplete'}}
2008-05-20 13:22:08 +08:00
struct Incomplete * I1 = & ( struct Incomplete ) { 1 , 2 , 3 } ; // -expected-error {{variable has incomplete type}}
void IncompleteFunc ( unsigned x ) {
struct Incomplete * I2 = ( struct foo [ x ] ) { 1 , 2 , 3 } ; // -expected-error {{variable-sized object may not be initialized}}
2008-05-20 13:25:56 +08:00
( void ) { 1 , 2 , 3 } ; // -expected-error {{variable has incomplete type}}
2008-11-24 14:25:27 +08:00
( void ( void ) ) { 0 } ; // -expected-error{{illegal initializer type 'void (void)'}}
2008-05-20 13:22:08 +08:00
}
2010-01-20 06:33:45 +08:00
// PR6080
int array [ ( sizeof ( int [ 3 ] ) = = sizeof ( ( int [ ] ) { 0 , 1 , 2 } ) ) ? 1 : - 1 ] ;