brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.2 KiB · e2ce2fd Raw
87 lines · c
1// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c11 -Wno-unused-value2 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  int b : 33; // expected-error{{width of bit-field 'b' (33 bits) exceeds the width of its type (32 bits)}}9 10  int c : (1 + 0.25); // expected-error{{integer constant expression must have integer type}}11  int d : (int)(1 + 0.25);12 13  int e : 0;  // expected-error {{bit-field 'e' has zero width}}14 15  float xx : 4;  // expected-error {{bit-field 'xx' has non-integral type}}16 17  // PR360718  enum e0 f : 1; // expected-error {{field has incomplete type 'enum e0'}}19 20  int g : (_Bool)1;21 22  // PR401723  char : 10;      // expected-error {{width of anonymous bit-field (10 bits) exceeds the width of its type (8 bits)}}24  unsigned : -2;  // expected-error {{anonymous bit-field has negative width (-2)}}25  float : 12;     // expected-error {{anonymous bit-field has non-integral type 'float'}}26 27  _Bool : 2;   // expected-error {{width of anonymous bit-field (2 bits) exceeds the width of its type (1 bit)}}28  _Bool h : 5; // expected-error {{width of bit-field 'h' (5 bits) exceeds the width of its type (1 bit)}}29};30 31struct b {unsigned x : 2;} x;32__typeof__(x.x+1) y;33int y;34 35struct {unsigned x : 2;} x2;36__typeof__((x.x+=1)+1) y;37__typeof__((0,x.x)+1) y;38__typeof__(x.x<<1) y;39int y;40 41struct PR8025 {42  double : 2; // expected-error{{anonymous bit-field has non-integral type 'double'}}43};44 45struct Test4 {46  unsigned bitX : 4;47  unsigned bitY : 4;48  unsigned var;49};50void test4(struct Test4 *t) {51  (void) sizeof(t->bitX); // expected-error {{invalid application of 'sizeof' to bit-field}}52  (void) sizeof((t->bitY)); // expected-error {{invalid application of 'sizeof' to bit-field}}53  (void) sizeof(t->bitX = 4); // not a bitfield designator in C54  (void) sizeof(t->bitX += 4); // not a bitfield designator in C55  (void) sizeof((void) 0, t->bitX); // not a bitfield designator in C56  (void) sizeof(t->var ? t->bitX : t->bitY); // not a bitfield designator in C57  (void) sizeof(t->var ? t->bitX : t->bitX); // not a bitfield designator in C58}59 60typedef unsigned Unsigned;61typedef signed Signed;62 63struct Test5 { unsigned n : 2; } t5;64// Bitfield is unsigned65struct Test5 sometest5 = {-1};66typedef __typeof__(+t5.n) Signed;  // ... but promotes to signed.67 68typedef __typeof__(t5.n + 0) Signed; // Arithmetic promotes.69 70typedef __typeof__(+(t5.n = 0)) Signed;  // FIXME: Assignment should not; the result71typedef __typeof__(+(t5.n += 0)) Signed; // is a non-bit-field lvalue of type unsigned.72typedef __typeof__(+(t5.n *= 0)) Signed;73 74typedef __typeof__(+(++t5.n)) Signed; // FIXME: Increment is equivalent to compound-assignment.75typedef __typeof__(+(--t5.n)) Signed; // This should not promote to signed.76 77typedef __typeof__(+(t5.n++)) Unsigned; // Post-increment is underspecified, but seems to78typedef __typeof__(+(t5.n--)) Unsigned; // also act like compound-assignment.79 80struct Test6 {81  : 0.0; // expected-error{{type name requires a specifier or qualifier}}82};83 84struct PR36157 {85  int n : 1 ? 1 : implicitly_declare_function(); // expected-error {{call to undeclared function 'implicitly_declare_function'; ISO C99 and later do not support implicit function declarations}}86};87