xref: /netbsd-src/tests/usr.bin/xlint/lint1/expr_promote.c (revision 5f2f42719cd62ff11fd913b40b7ce19f07c4fd25)
1 /*	$NetBSD: expr_promote.c,v 1.2 2021/08/16 20:27:31 rillig Exp $	*/
2 # 3 "expr_promote.c"
3 
4 /*
5  * Test arithmetic promotions in C90 and later.
6  */
7 
8 /* lint1-flags: -Sw */
9 
10 void sink(const char *, ...);
11 
12 struct arithmetic_types {
13 	_Bool boolean;
14 	char plain_char;
15 	signed char signed_char;
16 	unsigned char unsigned_char;
17 	short signed_short;
18 	unsigned short unsigned_short;
19 	int signed_int;
20 	unsigned int unsigned_int;
21 	long signed_long;
22 	unsigned long unsigned_long;
23 	long long signed_long_long;
24 	unsigned long long unsigned_long_long;
25 	float float_floating;
26 	double double_floating;
27 	long double long_floating;
28 	float _Complex float_complex;
29 	double _Complex double_complex;
30 	long double _Complex long_double_complex;
31 	enum {
32 		E
33 	} enumerator;
34 };
35 
36 void
37 caller(struct arithmetic_types *arg)
38 {
39 	sink("",
40 	    arg->boolean,		/* gets promoted to 'int' */
41 	    arg->plain_char,		/* gets promoted to 'int' */
42 	    arg->signed_char,		/* gets promoted to 'int' */
43 	    arg->unsigned_char,		/* gets promoted to 'int' */
44 	    arg->signed_short,		/* gets promoted to 'int' */
45 	    arg->unsigned_short,	/* gets promoted to 'int' */
46 	    arg->signed_int,
47 	    arg->unsigned_int,
48 	    arg->signed_long,
49 	    arg->unsigned_long,
50 	    arg->signed_long_long,
51 	    arg->unsigned_long_long,
52 	    arg->float_floating,	/* gets promoted to 'double' */
53 	    arg->double_floating,
54 	    arg->long_floating,
55 	    arg->float_complex,
56 	    arg->double_complex,
57 	    arg->long_double_complex,
58 	    arg->enumerator);
59 }
60 
61 /*
62  * XXX: _Bool should be promoted to 'int', C99 6.3.1.1p2 "If an int can
63  * represent ...".
64  */
65 /*
66  * XXX: Enumerations may need be promoted to 'int', at least C99 6.3.1.1p2
67  * suggests that: "If an int can represent ...".
68  */
69