init.c revision 7727acf243ee61c0757d86c95b69dbee56a3d898
1// RUN: %clang_cc1 %s -verify -fsyntax-only 2 3#include <stddef.h> 4#include <stdint.h> 5 6typedef void (* fp)(void); 7void foo(void); 8 9// PR clang/3377 10fp a[(short int)1] = { foo }; 11 12int myArray[5] = {1, 2, 3, 4, 5}; 13int *myPointer2 = myArray; 14int *myPointer = &(myArray[2]); 15 16 17extern int x; 18void *g = &x; 19int *h = &x; 20 21int test() { 22int a[10]; 23int b[10] = a; // expected-error {{array initializer must be an initializer list}} 24int +; // expected-error {{expected identifier or '('}} 25} 26 27 28// PR2050 29struct cdiff_cmd { 30 const char *name; 31 unsigned short argc; 32 int (*handler)(); 33}; 34int cdiff_cmd_open(); 35struct cdiff_cmd commands[] = { 36 {"OPEN", 1, &cdiff_cmd_open } 37}; 38 39// PR2348 40static struct { int z; } s[2]; 41int *t = &(*s).z; 42 43// PR2349 44short *a2(void) 45{ 46 short int b; 47 static short *bp = &b; // expected-error {{initializer element is not a compile-time constant}} 48 49 return bp; 50} 51 52int pbool(void) { 53 typedef const _Bool cbool; 54 _Bool pbool1 = (void *) 0; 55 cbool pbool2 = &pbool; 56 return pbool2; 57} 58 59 60// rdar://5870981 61union { float f; unsigned u; } u = { 1.0f }; 62 63// rdar://6156694 64int f3(int x) { return x; } 65typedef void (*vfunc)(void); 66void *bar = (vfunc) f3; 67 68// PR2747 69struct sym_reg { 70 char nc_gpreg; 71}; 72int sym_fw1a_scr[] = { 73 ((int)(&((struct sym_reg *)0)->nc_gpreg)) & 0, 74 8 * ((int)(&((struct sym_reg *)0)->nc_gpreg)) 75}; 76 77// PR3001 78struct s1 s2 = { // expected-error {{variable has incomplete type 'struct s1'}} \ 79 // expected-note {{forward declaration of 'struct s1'}} 80 .a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}} \ 81 // expected-note{{forward declaration of 'struct s3'}} 82 .b = bogus // expected-error {{use of undeclared identifier 'bogus'}} 83} 84 85// PR3382 86char t[] = ("Hello"); 87 88// <rdar://problem/6094855> 89typedef struct { } empty; 90 91typedef struct { 92 empty e; 93 int i2; 94} st; 95 96st st1 = { .i2 = 1 }; 97 98// <rdar://problem/6096826> 99struct { 100 int a; 101 int z[2]; 102} y = { .z = {} }; 103 104int bbb[10]; 105 106struct foo2 { 107 uintptr_t a; 108}; 109 110struct foo2 bar2[] = { 111 { (intptr_t)bbb } 112}; 113 114struct foo2 bar3 = { 1, 2 }; // expected-warning{{excess elements in struct initializer}} 115 116int* ptest1 = __builtin_choose_expr(1, (int*)0, (int*)0); 117 118typedef int32_t ivector4 __attribute((vector_size(16))); 119ivector4 vtest1 = 1 ? (ivector4){1} : (ivector4){1}; 120ivector4 vtest2 = __builtin_choose_expr(1, (ivector4){1}, (ivector4){1}); 121ivector4 vtest3 = __real__ (ivector4){1}; 122ivector4 vtest4 = __imag__ (ivector4){1}; 123 124uintptr_t ptrasintadd1 = (uintptr_t)&a - 4; 125uintptr_t ptrasintadd2 = (uintptr_t)&a + 4; 126uintptr_t ptrasintadd3 = 4 + (uintptr_t)&a; 127 128// PR4285 129const wchar_t widestr[] = L"asdf"; 130 131// PR5447 132const double pr5447 = (0.05 < -1.0) ? -1.0 : 0.0499878; 133 134