gcc_bit_field_types.c revision 1.6
1/*	$NetBSD: gcc_bit_field_types.c,v 1.6 2022/01/15 14:22:03 rillig Exp $	*/
2# 3 "gcc_bit_field_types.c"
3
4/*
5 * https://gcc.gnu.org/onlinedocs/gcc/Structures-unions-enumerations-and-bit-fields-implementation.html
6 *
7 * "Other integer types, such as long int, and enumerated types are permitted
8 * even in strictly conforming mode."
9 *
10 * See msg_035.c.
11 */
12
13struct example {
14	int int_flag: 1;
15	unsigned int unsigned_int_flag: 1;
16	long long_flag: 1;
17	unsigned long unsigned_long_flag: 1;
18	long long long_long_flag: 1;
19	unsigned long long unsigned_long_long_flag: 1;
20	/* expect+1: warning: illegal bit-field type 'double' [35] */
21	double double_flag: 1;
22};
23
24struct large_bit_field {
25	unsigned long long member: 48;
26};
27
28unsigned long long
29promote_large_bit_field(struct large_bit_field lbf)
30{
31	/*
32	 * Before tree.c 1.281 from 2021-05-04:
33	 * lint: assertion "len == size_in_bits(INT)" failed
34	 *     in promote at tree.c:1698
35	 */
36	return lbf.member & 0xf;
37}
38