Daniel Dunbar | 8fbe78f | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -fsyntax-only -verify |
Douglas Gregor | 8145742 | 2009-03-10 21:58:27 +0000 | [diff] [blame] | 2 | enum e0; // expected-note{{forward declaration of 'enum e0'}} |
Anders Carlsson | 5df391e | 2008-12-06 20:33:04 +0000 | [diff] [blame] | 3 | |
| 4 | struct a { |
| 5 | int a : -1; // expected-error{{bit-field 'a' has negative width}} |
Chris Lattner | ece9ae7 | 2008-12-11 23:11:52 +0000 | [diff] [blame] | 6 | |
| 7 | // rdar://6081627 |
Anders Carlsson | 7a4a25d | 2010-04-15 18:47:32 +0000 | [diff] [blame] | 8 | int b : 33; // expected-error{{size of bit-field 'b' (33 bits) exceeds size of its type (32 bits)}} |
Chris Lattner | ece9ae7 | 2008-12-11 23:11:52 +0000 | [diff] [blame] | 9 | |
Anders Carlsson | 5df391e | 2008-12-06 20:33:04 +0000 | [diff] [blame] | 10 | int c : (1 + 0.25); // expected-error{{expression is not an integer constant expression}} |
| 11 | int d : (int)(1 + 0.25); |
Chris Lattner | 81ed680 | 2008-12-12 04:56:04 +0000 | [diff] [blame] | 12 | |
| 13 | // rdar://6138816 |
| 14 | int e : 0; // expected-error {{bit-field 'e' has zero width}} |
Chris Lattner | 73bf7b4 | 2009-03-05 22:45:59 +0000 | [diff] [blame] | 15 | |
| 16 | float xx : 4; // expected-error {{bit-field 'xx' has non-integral type}} |
| 17 | |
| 18 | // PR3607 |
| 19 | enum e0 f : 1; // expected-error {{field has incomplete type 'enum e0'}} |
Anders Carlsson | 6caa9dd | 2009-03-16 18:19:21 +0000 | [diff] [blame] | 20 | |
| 21 | int g : (_Bool)1; |
Chris Lattner | f9b00eb | 2009-04-20 17:29:38 +0000 | [diff] [blame] | 22 | |
| 23 | // PR4017 |
Anders Carlsson | 7a4a25d | 2010-04-15 18:47:32 +0000 | [diff] [blame] | 24 | char : 10; // expected-error {{size of anonymous bit-field (10 bits) exceeds size of its type (8 bits)}} |
Chris Lattner | f9b00eb | 2009-04-20 17:29:38 +0000 | [diff] [blame] | 25 | unsigned : -2; // expected-error {{anonymous bit-field has negative width (-2)}} |
| 26 | float : 12; // expected-error {{anonymous bit-field has non-integral type 'float'}} |
Anders Carlsson | 5df391e | 2008-12-06 20:33:04 +0000 | [diff] [blame] | 27 | }; |
Douglas Gregor | 8d9c509 | 2009-05-01 20:41:21 +0000 | [diff] [blame] | 28 | |
| 29 | struct b {unsigned x : 2;} x; |
| 30 | __typeof__(x.x+1) y; |
| 31 | int y; |
Douglas Gregor | d2c2d17 | 2009-05-02 00:36:19 +0000 | [diff] [blame] | 32 | |
| 33 | struct {unsigned x : 2;} x2; |
Douglas Gregor | 71235ec | 2009-05-02 02:18:30 +0000 | [diff] [blame] | 34 | __typeof__((x.x+=1)+1) y; |
Eli Friedman | 609ada2 | 2011-07-13 02:05:57 +0000 | [diff] [blame] | 35 | __typeof__((0,x.x)+1) y; |
Douglas Gregor | d2c2d17 | 2009-05-02 00:36:19 +0000 | [diff] [blame] | 36 | __typeof__(x.x<<1) y; |
| 37 | int y; |
Douglas Gregor | 23ab745 | 2010-11-09 03:31:16 +0000 | [diff] [blame] | 38 | |
| 39 | struct PR8025 { |
| 40 | double : 2; // expected-error{{anonymous bit-field has non-integral type 'double'}} |
| 41 | }; |
John McCall | d25db7e | 2013-05-06 21:39:12 +0000 | [diff] [blame] | 42 | |
| 43 | struct Test4 { |
| 44 | unsigned bitX : 4; |
| 45 | unsigned bitY : 4; |
| 46 | unsigned var; |
| 47 | }; |
| 48 | void test4(struct Test4 *t) { |
| 49 | (void) sizeof(t->bitX); // expected-error {{invalid application of 'sizeof' to bit-field}} |
| 50 | (void) sizeof((t->bitY)); // expected-error {{invalid application of 'sizeof' to bit-field}} |
| 51 | (void) sizeof(t->bitX = 4); // not a bitfield designator in C |
| 52 | (void) sizeof(t->bitX += 4); // not a bitfield designator in C |
| 53 | (void) sizeof((void) 0, t->bitX); // not a bitfield designator in C |
| 54 | (void) sizeof(t->var ? t->bitX : t->bitY); // not a bitfield designator in C |
| 55 | (void) sizeof(t->var ? t->bitX : t->bitX); // not a bitfield designator in C |
| 56 | } |