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