xref: /netbsd-src/tests/usr.bin/xlint/lint1/expr_binary_trad.c (revision b2baa50111d645353fa30b4deab0f79d93650c8c)
1 /*	$NetBSD: expr_binary_trad.c,v 1.3 2023/03/28 14:44:34 rillig Exp $	*/
2 # 3 "expr_binary_trad.c"
3 
4 /*
5  * Test binary operators in traditional C.
6  */
7 
8 /* lint1-flags: -tw -X 351 */
9 
10 struct incompatible {		/* just to generate the error message */
11 	int member;
12 };
13 struct incompatible sink;
14 
15 /*
16  * Test the usual arithmetic conversions.
17  *
18  * C99 6.3.1.8 "Usual arithmetic conversions"
19  */
20 void
cover_balance()21 cover_balance()
22 {
23 
24 	/* expect+1: ... 'pointer to char' ... */
25 	sink = (char *)0 + 0;
26 
27 	/* expect+1: ... 'pointer to char' ... */
28 	sink = 0 + (char *)0;
29 
30 	/* expect+1: ... 'int' ... */
31 	sink = 1 + 1;
32 
33 	/* expect+1: ... 'double' ... */
34 	sink = 0.0 + 0;
35 	/* expect+1: ... 'double' ... */
36 	sink = 0 + 0.0;
37 	/* expect+1: ... 'double' ... */
38 	sink = 0.0 + (float)0.0;
39 	/* expect+1: ... 'double' ... */
40 	sink = (float)0.0 + 0.0;
41 
42 	/*
43 	 * In traditional C, 'float' gets promoted to 'double' before
44 	 * applying the usual arithmetic conversions; see 'promote'.
45 	 */
46 	/* expect+1: ... 'double' ... */
47 	sink = (float)0.0 + 0;
48 	/* expect+1: ... 'double' ... */
49 	sink = 0 + (float)0.0;
50 
51 	/* expect+1: ... 'unsigned long' ... */
52 	sink = (unsigned long)0 + 0;
53 	/* expect+1: ... 'unsigned long' ... */
54 	sink = 0 + (unsigned long)0;
55 
56 	/* expect+1: ... 'unsigned long' ... */
57 	sink = (unsigned long)0 + (long)0;
58 	/* expect+1: ... 'unsigned long' ... */
59 	sink = (long)0 + (unsigned long)0;
60 
61 	/*
62 	 * In traditional C, if one of the operands is unsigned, the result
63 	 * is unsigned as well.
64 	 */
65 	/* expect+1: ... 'unsigned long' ... */
66 	sink = (unsigned)0 + (long)0;
67 }
68