1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s 2b774d73540ba62a5e6a8e9217b320b27a946cfadNAKAMURA Takumi// REQUIRES: LP64 3e6386394677ed4f77b20e2e3d5446a3a2f628e53Steve Naroff 4e6386394677ed4f77b20e2e3d5446a3a2f628e53Steve Naroffstruct foo { int a, b; }; 5e6386394677ed4f77b20e2e3d5446a3a2f628e53Steve Naroff 69a979c327c442597c6a9cee961336530460fed04Nuno Lopesstatic struct foo t = (struct foo){0,0}; 75cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnarastatic struct foo t1 = __builtin_choose_expr(0, (struct foo){0,0}, (struct foo){0,0}); 85cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnarastatic struct foo t2 = {0,0}; 94a529d26d6ccfc9b3d11031f1256f4f87055c562Andy Gibbsstatic struct foo t3 = t2; // expected-error {{initializer element is not a compile-time constant}} 105cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnarastatic int *p = (int []){2,4}; 11759f25237864f3a3cc23eb01f0c0ce6edcc9342dEli Friedmanstatic int x = (int){1}; 12b8f13a8baff3df080fe024fec47746e9a79fe649Steve Naroff 134a529d26d6ccfc9b3d11031f1256f4f87055c562Andy Gibbsstatic int *p2 = (int []){2,x}; // expected-error {{initializer element is not a compile-time constant}} 144a529d26d6ccfc9b3d11031f1256f4f87055c562Andy Gibbsstatic long *p3 = (long []){2,"x"}; // expected-warning {{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char [2]'}} 1558d1821279b0ffd002e675d211faca3b5de067e2Steve Naroff 164a529d26d6ccfc9b3d11031f1256f4f87055c562Andy Gibbstypedef struct { } cache_t; // expected-warning{{empty struct is a GNU extension}} 174a529d26d6ccfc9b3d11031f1256f4f87055c562Andy Gibbsstatic cache_t clo_I1_cache = ((cache_t) { } ); // expected-warning{{use of GNU empty initializer extension}} 189a979c327c442597c6a9cee961336530460fed04Nuno Lopes 19e9b12198c4cc7f5687960100351b4af006c14469Steve Narofftypedef struct Test {int a;int b;} Test; 20e9b12198c4cc7f5687960100351b4af006c14469Steve Naroffstatic Test* ll = &(Test) {0,0}; 21e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff 22e6386394677ed4f77b20e2e3d5446a3a2f628e53Steve Naroffextern void fooFunc(struct foo *pfoo); 23e6386394677ed4f77b20e2e3d5446a3a2f628e53Steve Naroff 24e6386394677ed4f77b20e2e3d5446a3a2f628e53Steve Naroffint main(int argc, char **argv) { 2558d1821279b0ffd002e675d211faca3b5de067e2Steve Naroff int *l = (int []){x, *p, *p2}; 26e6386394677ed4f77b20e2e3d5446a3a2f628e53Steve Naroff fooFunc(&(struct foo){ 1, 2 }); 27e6386394677ed4f77b20e2e3d5446a3a2f628e53Steve Naroff} 28e6386394677ed4f77b20e2e3d5446a3a2f628e53Steve Naroff 294ec339f43c0cae2678334850c90926bea10999c7Douglas Gregorstruct Incomplete; // expected-note{{forward declaration of 'struct Incomplete'}} 304a529d26d6ccfc9b3d11031f1256f4f87055c562Andy Gibbsstruct Incomplete* I1 = &(struct Incomplete){1, 2, 3}; // expected-error {{variable has incomplete type}} 316223c2237052dc99cc5263d4cf20cb0bff7650cdEli Friedmanvoid IncompleteFunc(unsigned x) { 324a529d26d6ccfc9b3d11031f1256f4f87055c562Andy Gibbs struct Incomplete* I2 = (struct foo[x]){1, 2, 3}; // expected-error {{variable-sized object may not be initialized}} 334a529d26d6ccfc9b3d11031f1256f4f87055c562Andy Gibbs (void){1,2,3}; // expected-error {{variable has incomplete type}} 344a529d26d6ccfc9b3d11031f1256f4f87055c562Andy Gibbs (void(void)) { 0 }; // expected-error{{illegal initializer type 'void (void)'}} 356223c2237052dc99cc5263d4cf20cb0bff7650cdEli Friedman} 361d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 371d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall// PR6080 381d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCallint array[(sizeof(int[3]) == sizeof( (int[]) {0,1,2} )) ? 1 : -1]; 39