2015-10-08 18:04:46 +08:00
|
|
|
// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c11 -Wno-unused-value
|
2014-12-18 05:57:17 +08:00
|
|
|
|
2009-03-11 05:58:27 +08:00
|
|
|
enum e0; // expected-note{{forward declaration of 'enum e0'}}
|
2008-12-07 04:33:04 +08:00
|
|
|
|
|
|
|
struct a {
|
|
|
|
int a : -1; // expected-error{{bit-field 'a' has negative width}}
|
2008-12-12 07:11:52 +08:00
|
|
|
|
|
|
|
// rdar://6081627
|
2015-09-15 05:27:36 +08:00
|
|
|
int b : 33; // expected-error{{width of bit-field 'b' (33 bits) exceeds width of its type (32 bits)}}
|
2008-12-12 07:11:52 +08:00
|
|
|
|
2008-12-07 04:33:04 +08:00
|
|
|
int c : (1 + 0.25); // expected-error{{expression is not an integer constant expression}}
|
|
|
|
int d : (int)(1 + 0.25);
|
2008-12-12 12:56:04 +08:00
|
|
|
|
|
|
|
// rdar://6138816
|
|
|
|
int e : 0; // expected-error {{bit-field 'e' has zero width}}
|
2009-03-06 06:45:59 +08:00
|
|
|
|
|
|
|
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'}}
|
2009-03-17 02:19:21 +08:00
|
|
|
|
|
|
|
int g : (_Bool)1;
|
2009-04-21 01:29:38 +08:00
|
|
|
|
|
|
|
// PR4017
|
2015-09-15 05:27:36 +08:00
|
|
|
char : 10; // expected-error {{width of anonymous bit-field (10 bits) exceeds width of its type (8 bits)}}
|
2009-04-21 01:29:38 +08:00
|
|
|
unsigned : -2; // expected-error {{anonymous bit-field has negative width (-2)}}
|
|
|
|
float : 12; // expected-error {{anonymous bit-field has non-integral type 'float'}}
|
2015-09-15 05:27:36 +08:00
|
|
|
|
|
|
|
_Bool : 2; // expected-error {{width of anonymous bit-field (2 bits) exceeds width of its type (1 bit)}}
|
|
|
|
_Bool h : 5; // expected-error {{width of bit-field 'h' (5 bits) exceeds width of its type (1 bit)}}
|
2008-12-07 04:33:04 +08:00
|
|
|
};
|
2009-05-02 04:41:21 +08:00
|
|
|
|
|
|
|
struct b {unsigned x : 2;} x;
|
|
|
|
__typeof__(x.x+1) y;
|
|
|
|
int y;
|
2009-05-02 08:36:19 +08:00
|
|
|
|
|
|
|
struct {unsigned x : 2;} x2;
|
2009-05-02 10:18:30 +08:00
|
|
|
__typeof__((x.x+=1)+1) y;
|
2011-07-13 10:05:57 +08:00
|
|
|
__typeof__((0,x.x)+1) y;
|
2009-05-02 08:36:19 +08:00
|
|
|
__typeof__(x.x<<1) y;
|
|
|
|
int y;
|
2010-11-09 11:31:16 +08:00
|
|
|
|
|
|
|
struct PR8025 {
|
|
|
|
double : 2; // expected-error{{anonymous bit-field has non-integral type 'double'}}
|
|
|
|
};
|
2013-05-07 05:39:12 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2014-09-25 07:55:00 +08:00
|
|
|
|
|
|
|
typedef unsigned Unsigned;
|
|
|
|
typedef signed Signed;
|
|
|
|
|
|
|
|
struct Test5 { unsigned n : 2; } t5;
|
2015-11-11 10:02:15 +08:00
|
|
|
// Bitfield is unsigned
|
2016-08-05 10:39:30 +08:00
|
|
|
struct Test5 sometest5 = {-1};
|
2014-09-25 07:55:00 +08:00
|
|
|
typedef __typeof__(+t5.n) Signed; // ... but promotes to signed.
|
|
|
|
|
|
|
|
typedef __typeof__(t5.n + 0) Signed; // Arithmetic promotes.
|
|
|
|
|
|
|
|
typedef __typeof__(+(t5.n = 0)) Signed; // FIXME: Assignment should not; the result
|
|
|
|
typedef __typeof__(+(t5.n += 0)) Signed; // is a non-bit-field lvalue of type unsigned.
|
|
|
|
typedef __typeof__(+(t5.n *= 0)) Signed;
|
|
|
|
|
|
|
|
typedef __typeof__(+(++t5.n)) Signed; // FIXME: Increment is equivalent to compound-assignment.
|
|
|
|
typedef __typeof__(+(--t5.n)) Signed; // This should not promote to signed.
|
|
|
|
|
|
|
|
typedef __typeof__(+(t5.n++)) Unsigned; // Post-increment is underspecified, but seems to
|
|
|
|
typedef __typeof__(+(t5.n--)) Unsigned; // also act like compound-assignment.
|
2015-04-26 12:58:18 +08:00
|
|
|
|
|
|
|
struct Test6 {
|
|
|
|
: 0.0; // expected-error{{type name requires a specifier or qualifier}}
|
|
|
|
};
|
2018-02-02 04:01:49 +08:00
|
|
|
|
|
|
|
struct PR36157 {
|
|
|
|
int n : 1 ? 1 : implicitly_declare_function(); // expected-warning {{invalid in C99}}
|
|
|
|
};
|