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};
|
2008-01-09 08:05:37 +08:00
|
|
|
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}}
|
2008-01-09 08:05:37 +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}}
|
2008-11-13 05:19:11 +08:00
|
|
|
static long *p3 = (long []){2,"x"}; // -expected-warning {{incompatible pointer to integer conversion initializing 'char [2]', expected 'long'}}
|
2008-01-10 04:58:06 +08:00
|
|
|
|
2008-07-08 00:46:50 +08:00
|
|
|
typedef struct { } cache_t; // -expected-warning{{use of empty struct extension}}
|
|
|
|
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];
|