1 /* $NetBSD: msg_242.c,v 1.8 2023/07/09 11:01:27 rillig Exp $ */
2 # 3 "msg_242.c"
3
4 // Test for message: combination of '%s' and '%s', op '%s' [242]
5
6 /* lint1-extra-flags: -e -X 351 */
7
8 enum E {
9 E1
10 };
11
12 void sink_enum(enum E);
13 void sink_int(int);
14
15 void
example(enum E e,int i)16 example(enum E e, int i)
17 {
18 enum E e2 = e;
19 /* expect+1: warning: initialization of 'enum E' with 'int' [277] */
20 enum E e3 = i;
21 /* expect+1: warning: initialization of 'int' with 'enum E' [277] */
22 int i2 = e;
23 int i3 = i;
24
25 /* expect+1: warning: combination of 'enum E' and 'int', op '=' [242] */
26 e3 = i;
27 /* expect+1: warning: combination of 'int' and 'enum E', op '=' [242] */
28 i2 = e;
29
30 sink_enum(e2);
31 sink_enum(e3);
32 sink_int(i2);
33 sink_int(i3);
34 }
35
36
37 /*
38 * In C, the only ways to create named compile-time integer constants are
39 * preprocessor macros or enum constants. All other expressions do not count
40 * as constant expressions, even if they are declared 'static const' or
41 * 'const'.
42 */
43 unsigned
unnamed_enum(void)44 unnamed_enum(void)
45 {
46 enum {
47 compile_time_constant = 2
48 };
49
50 unsigned i = 3;
51
52 /* expect+3: warning: dubious operation '*' on enum [241] */
53 /* FIXME: Combining 'unsigned int' with 'unsigned int' is OK. */
54 /* expect+1: warning: combination of 'unsigned int' and 'unsigned int', op '=' [242] */
55 i = compile_time_constant * i;
56 return i;
57 }
58