xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_204.c (revision 82d56013d7b633d116a93943de88e08335357a7c)
1 /*	$NetBSD: msg_204.c,v 1.6 2021/04/05 01:35:34 rillig Exp $	*/
2 # 3 "msg_204.c"
3 
4 // Test for message: controlling expressions must have scalar type [204]
5 
6 extern void
7 extern_function(void);
8 
9 void (*function_pointer)(void);
10 
11 /*
12  * Since func.c 1.39 from 2020-12-31 18:51:28, lint had produced an error
13  * when a controlling expression was a function.  Pointers to functions were
14  * ok though.
15  */
16 void
17 bug_between_2020_12_31_and_2021_01_08(void)
18 {
19 	if (extern_function)
20 		extern_function();
21 
22 	/*
23 	 * FIXME: For some reason, the ampersand is discarded in
24 	 *  build_address.  This only has a visible effect if the
25 	 *  t_spec in check_controlling_expression is evaluated too early,
26 	 *  as has been the case before func.c 1.52 from 2021-01-08.
27 	 */
28 	if (&extern_function)
29 		extern_function();
30 
31 	/* This one has always been ok since pointers are scalar types. */
32 	if (function_pointer)
33 		function_pointer();
34 }
35 
36 struct s {
37 	int member;
38 };
39 
40 union u {
41 	int member;
42 };
43 
44 enum e {
45 	E
46 };
47 
48 struct arr {
49 	int arr[4];
50 };
51 
52 /* C99 6.2.5p2 */
53 void if_Bool(_Bool b)			{ if (b) return; }
54 
55 /* C99 6.2.5p3 */
56 void if_char(char c)			{ if (c) return; }
57 
58 /* C99 6.2.5p4 */
59 void if_signed_char(signed char sc)	{ if (sc) return; }
60 void if_short_int(short s)		{ if (s) return; }
61 void if_int(int i)			{ if (i) return; }
62 void if_long_int(long int l)		{ if (l) return; }
63 void if_long_long_int(long long int ll)	{ if (ll) return; }
64 
65 /* C99 6.2.5p6 */
66 void if_unsigned_char(unsigned char uc)			{ if (uc) return; }
67 void if_unsigned_short_int(unsigned short us)		{ if (us) return; }
68 void if_unsigned_int(unsigned int ui)			{ if (ui) return; }
69 void if_unsigned_long_int(unsigned long int ul)		{ if (ul) return; }
70 void if_unsigned_long_long_int(unsigned long long int ull) { if (ull) return; }
71 
72 /* C99 6.2.5p10 */
73 void if_float(float f)			{ if (f) return; }
74 void if_double(double d)		{ if (d) return; }
75 void if_long_double(long double ld)	{ if (ld) return; }
76 
77 /* C99 6.2.5p11 */
78 void if_float_Complex(float _Complex fc)		{ if (fc) return; }
79 void if_double_Complex(double _Complex dc)		{ if (dc) return; }
80 void if_long_double_Complex(long double _Complex ldc)	{ if (ldc) return; }
81 
82 /* C99 6.2.5p16 */
83 void if_enum(enum e e)			{ if (e) return; }
84 
85 /* C99 6.2.5p20 */
86 void if_array(struct arr arr)		{ if (arr.arr) return; }
87 void if_struct(struct s s)		{ if (s) return; }	/* expect: 204 *//* expect: 231 */
88 void if_union(union u u)		{ if (u) return; }	/* expect: 204 *//* expect: 231 */
89 void if_function(void)			{ if (if_function) return; }
90 void if_pointer(void *p)		{ if (p) return; }
91 
92 /* C99 6.8.5 */
93 void while_struct(struct s s)		{ while (s) return; }	/* expect: 204 *//* expect: 231 */
94 void for_struct(struct s s)		{ for (;s;) return; }	/* expect: 204 *//* expect: 223 *//* expect: 231 */
95 void do_while_struct(struct s s)	{ do { return; } while (s); }	/* expect: 204 *//* expect: 231 */
96 
97 /*
98  * C99 6.5.15 for the '?:' operator does not explicitly mention that the
99  * controlling expression must have a scalar type, curiously.
100  */
101 int conditional_struct(struct s s)	{ return s ? 1 : 2; }	/* expect: 170 *//* expect: 214 *//* expect: 231 */
102