blob: ab05a7773d945c9153bd47099aee3f1149948016 [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 %s -fsyntax-only -verify
Douglas Gregor81457422009-03-10 21:58:27 +00002enum e0; // expected-note{{forward declaration of 'enum e0'}}
Anders Carlsson5df391e2008-12-06 20:33:04 +00003
4struct a {
5 int a : -1; // expected-error{{bit-field 'a' has negative width}}
Chris Lattnerece9ae72008-12-11 23:11:52 +00006
7 // rdar://6081627
Anders Carlsson7a4a25d2010-04-15 18:47:32 +00008 int b : 33; // expected-error{{size of bit-field 'b' (33 bits) exceeds size of its type (32 bits)}}
Chris Lattnerece9ae72008-12-11 23:11:52 +00009
Anders Carlsson5df391e2008-12-06 20:33:04 +000010 int c : (1 + 0.25); // expected-error{{expression is not an integer constant expression}}
11 int d : (int)(1 + 0.25);
Chris Lattner81ed6802008-12-12 04:56:04 +000012
13 // rdar://6138816
14 int e : 0; // expected-error {{bit-field 'e' has zero width}}
Chris Lattner73bf7b42009-03-05 22:45:59 +000015
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 Carlsson6caa9dd2009-03-16 18:19:21 +000020
21 int g : (_Bool)1;
Chris Lattnerf9b00eb2009-04-20 17:29:38 +000022
23 // PR4017
Anders Carlsson7a4a25d2010-04-15 18:47:32 +000024 char : 10; // expected-error {{size of anonymous bit-field (10 bits) exceeds size of its type (8 bits)}}
Chris Lattnerf9b00eb2009-04-20 17:29:38 +000025 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 Carlsson5df391e2008-12-06 20:33:04 +000027};
Douglas Gregor8d9c5092009-05-01 20:41:21 +000028
29struct b {unsigned x : 2;} x;
30__typeof__(x.x+1) y;
31int y;
Douglas Gregord2c2d172009-05-02 00:36:19 +000032
33struct {unsigned x : 2;} x2;
Douglas Gregor71235ec2009-05-02 02:18:30 +000034__typeof__((x.x+=1)+1) y;
Eli Friedman609ada22011-07-13 02:05:57 +000035__typeof__((0,x.x)+1) y;
Douglas Gregord2c2d172009-05-02 00:36:19 +000036__typeof__(x.x<<1) y;
37int y;
Douglas Gregor23ab7452010-11-09 03:31:16 +000038
39struct PR8025 {
40 double : 2; // expected-error{{anonymous bit-field has non-integral type 'double'}}
41};
John McCalld25db7e2013-05-06 21:39:12 +000042
43struct Test4 {
44 unsigned bitX : 4;
45 unsigned bitY : 4;
46 unsigned var;
47};
48void 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}