1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -fsyntax-only -verify 2*f4a2713aSLionel Sambuc enum e0; // expected-note{{forward declaration of 'enum e0'}} 3*f4a2713aSLionel Sambuc 4*f4a2713aSLionel Sambuc struct a { 5*f4a2713aSLionel Sambuc int a : -1; // expected-error{{bit-field 'a' has negative width}} 6*f4a2713aSLionel Sambuc 7*f4a2713aSLionel Sambuc // rdar://6081627 8*f4a2713aSLionel Sambuc int b : 33; // expected-error{{size of bit-field 'b' (33 bits) exceeds size of its type (32 bits)}} 9*f4a2713aSLionel Sambuc 10*f4a2713aSLionel Sambuc int c : (1 + 0.25); // expected-error{{expression is not an integer constant expression}} 11*f4a2713aSLionel Sambuc int d : (int)(1 + 0.25); 12*f4a2713aSLionel Sambuc 13*f4a2713aSLionel Sambuc // rdar://6138816 14*f4a2713aSLionel Sambuc int e : 0; // expected-error {{bit-field 'e' has zero width}} 15*f4a2713aSLionel Sambuc 16*f4a2713aSLionel Sambuc float xx : 4; // expected-error {{bit-field 'xx' has non-integral type}} 17*f4a2713aSLionel Sambuc 18*f4a2713aSLionel Sambuc // PR3607 19*f4a2713aSLionel Sambuc enum e0 f : 1; // expected-error {{field has incomplete type 'enum e0'}} 20*f4a2713aSLionel Sambuc 21*f4a2713aSLionel Sambuc int g : (_Bool)1; 22*f4a2713aSLionel Sambuc 23*f4a2713aSLionel Sambuc // PR4017 24*f4a2713aSLionel Sambuc char : 10; // expected-error {{size of anonymous bit-field (10 bits) exceeds size of its type (8 bits)}} 25*f4a2713aSLionel Sambuc unsigned : -2; // expected-error {{anonymous bit-field has negative width (-2)}} 26*f4a2713aSLionel Sambuc float : 12; // expected-error {{anonymous bit-field has non-integral type 'float'}} 27*f4a2713aSLionel Sambuc }; 28*f4a2713aSLionel Sambuc 29*f4a2713aSLionel Sambuc struct b {unsigned x : 2;} x; 30*f4a2713aSLionel Sambuc __typeof__(x.x+1) y; 31*f4a2713aSLionel Sambuc int y; 32*f4a2713aSLionel Sambuc 33*f4a2713aSLionel Sambuc struct {unsigned x : 2;} x2; 34*f4a2713aSLionel Sambuc __typeof__((x.x+=1)+1) y; 35*f4a2713aSLionel Sambuc __typeof__((0,x.x)+1) y; 36*f4a2713aSLionel Sambuc __typeof__(x.x<<1) y; 37*f4a2713aSLionel Sambuc int y; 38*f4a2713aSLionel Sambuc 39*f4a2713aSLionel Sambuc struct PR8025 { 40*f4a2713aSLionel Sambuc double : 2; // expected-error{{anonymous bit-field has non-integral type 'double'}} 41*f4a2713aSLionel Sambuc }; 42*f4a2713aSLionel Sambuc 43*f4a2713aSLionel Sambuc struct Test4 { 44*f4a2713aSLionel Sambuc unsigned bitX : 4; 45*f4a2713aSLionel Sambuc unsigned bitY : 4; 46*f4a2713aSLionel Sambuc unsigned var; 47*f4a2713aSLionel Sambuc }; 48*f4a2713aSLionel Sambuc void test4(struct Test4 *t) { 49*f4a2713aSLionel Sambuc (void) sizeof(t->bitX); // expected-error {{invalid application of 'sizeof' to bit-field}} 50*f4a2713aSLionel Sambuc (void) sizeof((t->bitY)); // expected-error {{invalid application of 'sizeof' to bit-field}} 51*f4a2713aSLionel Sambuc (void) sizeof(t->bitX = 4); // not a bitfield designator in C 52*f4a2713aSLionel Sambuc (void) sizeof(t->bitX += 4); // not a bitfield designator in C 53*f4a2713aSLionel Sambuc (void) sizeof((void) 0, t->bitX); // not a bitfield designator in C 54*f4a2713aSLionel Sambuc (void) sizeof(t->var ? t->bitX : t->bitY); // not a bitfield designator in C 55*f4a2713aSLionel Sambuc (void) sizeof(t->var ? t->bitX : t->bitX); // not a bitfield designator in C 56*f4a2713aSLionel Sambuc } 57