summaryrefslogtreecommitdiff
path: root/tests/usr.bin/xlint/lint1/expr_promote.c
blob: a7af50bf11ec7a24dc164b9b52f90422c74ac0e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*	$NetBSD: expr_promote.c,v 1.4 2023/03/28 14:44:34 rillig Exp $	*/
# 3 "expr_promote.c"

/*
 * Test arithmetic promotions in C90 and later.
 */

/* lint1-flags: -Sw -X 351 */

void sink(const char *, ...);

struct arithmetic_types {
	_Bool boolean;
	char plain_char;
	signed char signed_char;
	unsigned char unsigned_char;
	short signed_short;
	unsigned short unsigned_short;
	int signed_int;
	unsigned int unsigned_int;
	long signed_long;
	unsigned long unsigned_long;
	long long signed_long_long;
	unsigned long long unsigned_long_long;
	float float_floating;
	double double_floating;
	long double long_floating;
	float _Complex float_complex;
	double _Complex double_complex;
	long double _Complex long_double_complex;
	enum {
		E
	} enumerator;
};

void
caller(struct arithmetic_types *arg)
{
	/* See expr_promote.exp-ln for the resulting types. */
	sink("",
	    arg->boolean,		/* gets promoted to 'int' */
	    arg->plain_char,		/* gets promoted to 'int' */
	    arg->signed_char,		/* gets promoted to 'int' */
	    arg->unsigned_char,		/* gets promoted to 'int' */
	    arg->signed_short,		/* gets promoted to 'int' */
	    arg->unsigned_short,	/* gets promoted to 'int' */
	    arg->signed_int,
	    arg->unsigned_int,
	    arg->signed_long,
	    arg->unsigned_long,
	    arg->signed_long_long,
	    arg->unsigned_long_long,
	    arg->float_floating,	/* gets promoted to 'double' */
	    arg->double_floating,
	    arg->long_floating,
	    arg->float_complex,
	    arg->double_complex,
	    arg->long_double_complex,
	    arg->enumerator);
}

/*
 * XXX: _Bool should be promoted to 'int', C99 6.3.1.1p2 "If an int can
 * represent ...".
 */
/*
 * XXX: Enumerations may need be promoted to 'int', at least C99 6.3.1.1p2
 * suggests that: "If an int can represent ...".
 */