1// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c11 -Wno-unused-value
2
3enum e0; // expected-note{{forward declaration of 'enum e0'}}
4
5struct a {
6  int a : -1; // expected-error{{bit-field 'a' has negative width}}
7
8  // rdar://6081627
9  int b : 33; // expected-error{{width of bit-field 'b' (33 bits) exceeds width of its type (32 bits)}}
10
11  int c : (1 + 0.25); // expected-error{{expression is not an integer constant expression}}
12  int d : (int)(1 + 0.25);
13
14  // rdar://6138816
15  int e : 0;  // expected-error {{bit-field 'e' has zero width}}
16
17  float xx : 4;  // expected-error {{bit-field 'xx' has non-integral type}}
18
19  // PR3607
20  enum e0 f : 1; // expected-error {{field has incomplete type 'enum e0'}}
21
22  int g : (_Bool)1;
23
24  // PR4017
25  char : 10;      // expected-error {{width of anonymous bit-field (10 bits) exceeds width of its type (8 bits)}}
26  unsigned : -2;  // expected-error {{anonymous bit-field has negative width (-2)}}
27  float : 12;     // expected-error {{anonymous bit-field has non-integral type 'float'}}
28
29  _Bool : 2;   // expected-error {{width of anonymous bit-field (2 bits) exceeds width of its type (1 bit)}}
30  _Bool h : 5; // expected-error {{width of bit-field 'h' (5 bits) exceeds width of its type (1 bit)}}
31};
32
33struct b {unsigned x : 2;} x;
34__typeof__(x.x+1) y;
35int y;
36
37struct {unsigned x : 2;} x2;
38__typeof__((x.x+=1)+1) y;
39__typeof__((0,x.x)+1) y;
40__typeof__(x.x<<1) y;
41int y;
42
43struct PR8025 {
44  double : 2; // expected-error{{anonymous bit-field has non-integral type 'double'}}
45};
46
47struct Test4 {
48  unsigned bitX : 4;
49  unsigned bitY : 4;
50  unsigned var;
51};
52void test4(struct Test4 *t) {
53  (void) sizeof(t->bitX); // expected-error {{invalid application of 'sizeof' to bit-field}}
54  (void) sizeof((t->bitY)); // expected-error {{invalid application of 'sizeof' to bit-field}}
55  (void) sizeof(t->bitX = 4); // not a bitfield designator in C
56  (void) sizeof(t->bitX += 4); // not a bitfield designator in C
57  (void) sizeof((void) 0, t->bitX); // not a bitfield designator in C
58  (void) sizeof(t->var ? t->bitX : t->bitY); // not a bitfield designator in C
59  (void) sizeof(t->var ? t->bitX : t->bitX); // not a bitfield designator in C
60}
61
62typedef unsigned Unsigned;
63typedef signed Signed;
64
65struct Test5 { unsigned n : 2; } t5;
66// Bitfield is unsigned
67struct Test5 sometest5 = {-1}; // expected-warning {{implicit truncation from 'int' to bitfield changes value from -1 to 3}}
68typedef __typeof__(+t5.n) Signed;  // ... but promotes to signed.
69
70typedef __typeof__(t5.n + 0) Signed; // Arithmetic promotes.
71
72typedef __typeof__(+(t5.n = 0)) Signed;  // FIXME: Assignment should not; the result
73typedef __typeof__(+(t5.n += 0)) Signed; // is a non-bit-field lvalue of type unsigned.
74typedef __typeof__(+(t5.n *= 0)) Signed;
75
76typedef __typeof__(+(++t5.n)) Signed; // FIXME: Increment is equivalent to compound-assignment.
77typedef __typeof__(+(--t5.n)) Signed; // This should not promote to signed.
78
79typedef __typeof__(+(t5.n++)) Unsigned; // Post-increment is underspecified, but seems to
80typedef __typeof__(+(t5.n--)) Unsigned; // also act like compound-assignment.
81
82struct Test6 {
83  : 0.0; // expected-error{{type name requires a specifier or qualifier}}
84};
85