1 /* $NetBSD: msg_155.c,v 1.12 2023/03/28 14:44:35 rillig Exp $ */
2 # 3 "msg_155.c"
3
4 // Test for message: passing '%s' to incompatible '%s', arg #%d [155]
5
6 /* lint1-extra-flags: -X 351 */
7
8
9 void c99_6_7_6_example_a(int);
10 void c99_6_7_6_example_b(int *);
11 void c99_6_7_6_example_c(int *[3]);
12 void c99_6_7_6_example_d(int (*)[3]);
13 void c99_6_7_6_example_e(int (*)[*]);
14 /* Wrong type before decl.c 1.256 from 2022-04-01. */
15 void c99_6_7_6_example_f(int *());
16 void c99_6_7_6_example_g(int (*)(void));
17 void c99_6_7_6_example_h(int (*const[])(unsigned int, ...));
18
19 struct incompatible {
20 int member;
21 };
22
23 void
provoke_error_messages(struct incompatible arg)24 provoke_error_messages(struct incompatible arg)
25 {
26 /* expect+1: ... 'int', ... */
27 c99_6_7_6_example_a(arg);
28
29 /* expect+1: ... 'pointer to int', ... */
30 c99_6_7_6_example_b(arg);
31
32 /* C99 says 'array[3] of pointer to int', which is close enough. */
33 /* expect+1: ... 'pointer to pointer to int', ... */
34 c99_6_7_6_example_c(arg);
35
36 /* expect+1: ... 'pointer to array[3] of int', ... */
37 c99_6_7_6_example_d(arg);
38
39 /* expect+1: ... 'pointer to array[unknown_size] of int', ... */
40 c99_6_7_6_example_e(arg);
41
42 /* Wrong type before decl.c 1.256 from 2022-04-01. */
43 /* expect+1: ... 'pointer to function() returning pointer to int', ... */
44 c99_6_7_6_example_f(arg);
45
46 /* expect+1: ... 'pointer to function(void) returning int', ... */
47 c99_6_7_6_example_g(arg);
48
49 /* expect+1: ... 'pointer to const pointer to function(unsigned int, ...) returning int', ... */
50 c99_6_7_6_example_h(arg);
51 }
52
53 extern void sink(struct incompatible);
54
55 /*
56 * The function type_name has a special case for an enum type that has been
57 * implicitly converted to an int. Such a type is still output as the enum
58 * type.
59 *
60 * XXX: The expressions 'day + 0' and '0 + day' should result in the same
61 * type.
62 */
63 void
type_name_of_enum(void)64 type_name_of_enum(void)
65 {
66 enum Day {
67 MONDAY
68 } day = MONDAY;
69
70 /* expect+1: ... passing 'enum Day' ... */
71 sink(day);
72
73 /* expect+1: ... passing 'enum Day' ... */
74 sink(day + 0);
75
76 /* expect+1: ... passing 'int' ... */
77 sink(0 + day);
78
79 /* expect+1: ... passing 'int' ... */
80 sink(0);
81 }
82