xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_035.c (revision 9fb66d812c00ebfb445c0b47dea128f32aa6fe96)
1 /*	$NetBSD: msg_035.c,v 1.8 2021/04/05 01:35:34 rillig Exp $	*/
2 # 3 "msg_035.c"
3 
4 // Test for message: illegal bit-field type '%s' [35]
5 
6 /*
7  * In traditional C, only unsigned int is a portable bit-field type.
8  *
9  * In C89, only int, signed int and unsigned int are allowed (3.5.2.1p7).
10  *
11  * In C99 and C11, only _Bool, signed int and unsigned int are allowed,
12  * plus implementation-defined types (6.7.2.1p5).
13  */
14 
15 typedef struct {
16 	int dummy;
17 } example_struct;
18 
19 typedef union {
20 	int dummy;
21 } example_union;
22 
23 typedef enum {
24 	NO, YES
25 } example_enum;
26 
27 typedef void (example_function)(int, const char *);
28 
29 /* Try all types from tspec_t. */
30 struct example {
31 	signed signed_flag: 1;
32 	unsigned unsigned_flag: 1;
33 	_Bool boolean_flag: 1;
34 	char char_flag: 1;
35 	signed char signed_char_flag: 1;
36 	unsigned char unsigned_char_flag: 1;
37 	short short_flag: 1;
38 	unsigned short unsigned_short_flag: 1;
39 	int int_flag: 1;
40 	unsigned int unsigned_int_flag: 1;
41 	long long_flag: 1;				/* expect: 35 */
42 	unsigned long unsigned_long_flag: 1;		/* expect: 35 */
43 	long long long_long_flag: 1;			/* expect: 35 */
44 	unsigned long long unsigned_long_long_flag: 1;	/* expect: 35 */
45 	/* __int128_t omitted since it is not always defined */
46 	/* __uint128_t omitted since it is not always defined */
47 	float float_flag: 1;				/* expect: 35 */
48 	double double_flag: 1;				/* expect: 35 */
49 	long double long_double_flag: 1;		/* expect: 35 */
50 	void void_flag: 1;				/* expect: 19 *//* expect: 37 */
51 	example_struct struct_flag: 1;			/* expect: 35 */
52 	example_union union_flag: 1;			/* expect: 35 */
53 	example_enum enum_flag: 1;
54 	void *pointer_flag: 1;				/* expect: 35 */
55 	unsigned int array_flag[4]: 1;			/* expect: 35 */
56 	example_function function_flag: 1;		/* expect: 35 */
57 	_Complex complex_flag: 1;			/* expect: 35 *//* expect: 308 */
58 	float _Complex float_complex_flag: 1;		/* expect: 35 */
59 	double _Complex double_complex_flag: 1;		/* expect: 35 */
60 	long double _Complex long_double_complex_flag: 1; /* expect: 35 */
61 };
62