init.c revision 7c53ca6e03833adab4465462b7d5c888741b715d
1// RUN: clang %s -verify -fsyntax-only 2 3#include <stdint.h> 4 5typedef void (* fp)(void); 6void foo(void); 7 8// PR clang/3377 9fp a[(short int)1] = { foo }; 10 11int myArray[5] = {1, 2, 3, 4, 5}; 12int *myPointer2 = myArray; 13int *myPointer = &(myArray[2]); 14 15 16extern int x; 17void *g = &x; 18int *h = &x; 19 20int test() { 21int a[10]; 22int b[10] = a; // expected-error {{initialization with '{...}' expected}} 23int +; // expected-error {{expected identifier or '('}} expected-error {{parse error}} 24} 25 26 27// PR2050 28struct cdiff_cmd { 29 const char *name; 30 unsigned short argc; 31 int (*handler)(); 32}; 33int cdiff_cmd_open(); 34struct cdiff_cmd commands[] = { 35 {"OPEN", 1, &cdiff_cmd_open } 36}; 37 38// PR2348 39static struct { int z; } s[2]; 40int *t = &(*s).z; 41 42// PR2349 43short *a2(void) 44{ 45 short int b; 46 static short *bp = &b; // expected-error {{initializer element is not a compile-time constant}} 47 48 return bp; 49} 50 51int pbool(void) { 52 typedef const _Bool cbool; 53 _Bool pbool1 = (void *) 0; 54 cbool pbool2 = &pbool; 55 return pbool2; 56} 57 58 59// rdar://5870981 60union { float f; unsigned u; } u = { 1.0f }; 61 62// rdar://6156694 63int f3(int x) { return x; } 64typedef void (*vfunc)(void); 65void *bar = (vfunc) f3; 66 67// PR2747 68struct sym_reg { 69 char nc_gpreg; 70}; 71int sym_fw1a_scr[] = { 72 ((int)(&((struct sym_reg *)0)->nc_gpreg)) & 0, 73 8 * ((int)(&((struct sym_reg *)0)->nc_gpreg)) 74}; 75 76// PR3001 77struct s1 s2 = { 78 .a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}} \ 79 // expected-note{{forward declaration of 'struct s3'}} 80 .b = bogus // expected-error {{use of undeclared identifier 'bogus'}} 81} 82 83// PR3382 84char t[] = ("Hello"); 85 86// <rdar://problem/6094855> 87typedef struct { } empty; 88 89typedef struct { 90 empty e; 91 int i2; 92} st; 93 94st st1 = { .i2 = 1 }; 95 96// <rdar://problem/6096826> 97struct { 98 int a; 99 int z[2]; 100} y = { .z = {} }; 101 102int bbb[10]; 103 104struct foo2 { 105 unsigned a; 106}; 107 108struct foo2 bar2[] = { 109 { (intptr_t)bbb } 110}; 111 112struct foo2 bar3 = { 1, 2 }; // expected-warning{{excess elements in struct initializer}} 113