init.c revision d7d5f0223bd30dfd618762349c6209dd1d5ea3e6
1// RUN: clang-cc %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 = { // expected-error{{tentative definition has type 'struct s1' that is never completed}} \ 78 // expected-note{{forward declaration of 'struct s1'}} 79 .a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}} \ 80 // expected-note{{forward declaration of 'struct s3'}} 81 .b = bogus // expected-error {{use of undeclared identifier 'bogus'}} 82} 83 84// PR3382 85char t[] = ("Hello"); 86 87// <rdar://problem/6094855> 88typedef struct { } empty; 89 90typedef struct { 91 empty e; 92 int i2; 93} st; 94 95st st1 = { .i2 = 1 }; 96 97// <rdar://problem/6096826> 98struct { 99 int a; 100 int z[2]; 101} y = { .z = {} }; 102 103int bbb[10]; 104 105struct foo2 { 106 uintptr_t a; 107}; 108 109struct foo2 bar2[] = { 110 { (intptr_t)bbb } 111}; 112 113struct foo2 bar3 = { 1, 2 }; // expected-warning{{excess elements in struct initializer}} 114 115int* ptest1 = __builtin_choose_expr(1, (int*)0, (int*)0); 116 117typedef int32_t ivector4 __attribute((vector_size(16))); 118ivector4 vtest1 = 1 ? (ivector4){1} : (ivector4){1}; 119ivector4 vtest2 = __builtin_choose_expr(1, (ivector4){1}, (ivector4){1}); 120ivector4 vtest3 = __real__ (ivector4){1}; 121ivector4 vtest4 = __imag__ (ivector4){1}; 122 123uintptr_t ptrasintadd1 = (uintptr_t)&a - 4; 124uintptr_t ptrasintadd2 = (uintptr_t)&a + 4; 125uintptr_t ptrasintadd3 = 4 + (uintptr_t)&a; 126