summaryrefslogtreecommitdiff
path: root/tests/usr.bin/xlint/lint1/expr_promote_trad.c
blob: 4f5fc88f19aee2232975bbafae0969cfa3158135 (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
/*	$NetBSD: expr_promote_trad.c,v 1.4 2023/03/28 14:44:34 rillig Exp $	*/
# 3 "expr_promote_trad.c"

/*
 * Test arithmetic promotions in traditional C.
 */

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

sink();

struct arithmetic_types {
	/* _Bool is not available in traditional C */
	char plain_char;
	/* signed char is not available in traditional C */
	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;
	/* (unsigned) long long is not available in traditional C */
	/* __int128_t is not available in traditional C */
	/* __uint128_t is not available in traditional C */
	float single_floating;
	double double_floating;
	/* long double is not available in traditional C */
	/* _Complex is not available in traditional C */
	enum {
		E
	} enumerator;
};

caller(arg)
	struct arithmetic_types *arg;
{
	/* See expr_promote_trad.exp-ln for the resulting types. */
	sink("",
	    arg->plain_char,		/* gets promoted to 'int' */
	    arg->unsigned_char,		/* gets promoted to 'unsigned int' */
	    arg->signed_short,		/* gets promoted to 'int' */
	    arg->unsigned_short,	/* gets promoted to 'unsigned int' */
	    arg->signed_int,
	    arg->unsigned_int,
	    arg->signed_long,
	    arg->unsigned_long,
	    arg->single_floating,	/* gets promoted to 'double' */
	    arg->double_floating,
	    arg->enumerator);
}

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