File: bitfield.c

package info (click to toggle)
llvm-toolchain-3.4 1%3A3.4.2-13
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 253,236 kB
  • ctags: 276,203
  • sloc: cpp: 1,665,580; ansic: 298,647; asm: 206,157; objc: 84,350; python: 73,119; sh: 23,466; perl: 5,679; makefile: 5,542; ml: 5,250; pascal: 2,467; lisp: 1,420; xml: 679; cs: 236; csh: 117
file content (56 lines) | stat: -rw-r--r-- 1,940 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// RUN: %clang_cc1 %s -fsyntax-only -verify 
enum e0; // expected-note{{forward declaration of 'enum e0'}}

struct a {
  int a : -1; // expected-error{{bit-field 'a' has negative width}}

  // rdar://6081627
  int b : 33; // expected-error{{size of bit-field 'b' (33 bits) exceeds size of its type (32 bits)}}

  int c : (1 + 0.25); // expected-error{{expression is not an integer constant expression}}
  int d : (int)(1 + 0.25); 

  // rdar://6138816
  int e : 0;  // expected-error {{bit-field 'e' has zero width}}

  float xx : 4;  // expected-error {{bit-field 'xx' has non-integral type}}

  // PR3607
  enum e0 f : 1; // expected-error {{field has incomplete type 'enum e0'}}
  
  int g : (_Bool)1;
  
  // PR4017  
  char : 10;      // expected-error {{size of anonymous bit-field (10 bits) exceeds size of its type (8 bits)}}
  unsigned : -2;  // expected-error {{anonymous bit-field has negative width (-2)}}
  float : 12;     // expected-error {{anonymous bit-field has non-integral type 'float'}}
};

struct b {unsigned x : 2;} x;
__typeof__(x.x+1) y;
int y;

struct {unsigned x : 2;} x2;
__typeof__((x.x+=1)+1) y;
__typeof__((0,x.x)+1) y;
__typeof__(x.x<<1) y;
int y;

struct PR8025 {
  double : 2; // expected-error{{anonymous bit-field has non-integral type 'double'}}
};

struct Test4 {
  unsigned bitX : 4;
  unsigned bitY : 4;
  unsigned var;
};
void test4(struct Test4 *t) {
  (void) sizeof(t->bitX); // expected-error {{invalid application of 'sizeof' to bit-field}}
  (void) sizeof((t->bitY)); // expected-error {{invalid application of 'sizeof' to bit-field}}
  (void) sizeof(t->bitX = 4); // not a bitfield designator in C
  (void) sizeof(t->bitX += 4); // not a bitfield designator in C
  (void) sizeof((void) 0, t->bitX); // not a bitfield designator in C
  (void) sizeof(t->var ? t->bitX : t->bitY); // not a bitfield designator in C
  (void) sizeof(t->var ? t->bitX : t->bitX); // not a bitfield designator in C
}