1 /*        $NetBSD: expr_promote.c,v 1.5 2024/11/05 04:53:28 rillig Exp $        */
2 # 3 "expr_promote.c"
3 
4 /*
5  * Test arithmetic promotions in C90 and later.
6  */
7 
8 /* lint1-flags: -Sw -X 351 */
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
caller(struct arithmetic_types * arg)37 caller(struct arithmetic_types *arg)
38 {
39           /* See expr_promote.exp-ln for the resulting types. */
40           sink("",
41               arg->boolean,             /* should get promoted to 'int' */
42               arg->plain_char,                    /* gets promoted to 'int' */
43               arg->signed_char,                   /* gets promoted to 'int' */
44               arg->unsigned_char,                 /* gets promoted to 'int' */
45               arg->signed_short,                  /* gets promoted to 'int' */
46               arg->unsigned_short,      /* gets promoted to 'int' */
47               arg->signed_int,
48               arg->unsigned_int,
49               arg->signed_long,
50               arg->unsigned_long,
51               arg->signed_long_long,
52               arg->unsigned_long_long,
53               arg->float_floating,      /* gets promoted to 'double' */
54               arg->double_floating,
55               arg->long_floating,
56               arg->float_complex,
57               arg->double_complex,
58               arg->long_double_complex,
59               arg->enumerator);                   /* should get promoted to 'int' */
60 }
61 
62 /*
63  * XXX: _Bool should be promoted to 'int', C99 6.3.1.1p2 "If an int can
64  * represent ...".
65  */
66 /*
67  * XXX: Enumerations may need be promoted to 'int', at least C99 6.3.1.1p2
68  * suggests that: "If an int can represent ...".
69  */
70