]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/g++.dg/diagnostic/param-type-mismatch.C
diagnostics: add labeling of source ranges
[thirdparty/gcc.git] / gcc / testsuite / g++.dg / diagnostic / param-type-mismatch.C
1 // { dg-options "-fdiagnostics-show-caret" }
2
3 /* A collection of calls where argument 2 is of the wrong type. */
4
5 /* decl, with argname. */
6
7 extern int callee_1 (int one, const char *two, float three); // { dg-line callee_1 }
8
9 int test_1 (int first, int second, float third)
10 {
11 return callee_1 (first, second, third); // { dg-error "invalid conversion from 'int' to 'const char\\*'" }
12 /* { dg-begin-multiline-output "" }
13 return callee_1 (first, second, third);
14 ^~~~~~
15 |
16 int
17 { dg-end-multiline-output "" } */
18 // { dg-message "initializing argument 2 of 'int callee_1\\(int, const char\\*, float\\)'" "" { target *-*-* } callee_1 }
19 /* { dg-begin-multiline-output "" }
20 extern int callee_1 (int one, const char *two, float three);
21 ~~~~~~~~~~~~^~~
22 { dg-end-multiline-output "" } */
23 }
24
25 /* decl, without argname. */
26
27 extern int callee_2 (int, const char *, float); // { dg-line callee_2 }
28
29 int test_2 (int first, int second, float third)
30 {
31 return callee_2 (first, second, third); // { dg-error "invalid conversion from 'int' to 'const char\\*'" }
32 /* { dg-begin-multiline-output "" }
33 return callee_2 (first, second, third);
34 ^~~~~~
35 |
36 int
37 { dg-end-multiline-output "" } */
38 // { dg-message "initializing argument 2 of 'int callee_2\\(int, const char\\*, float\\)'" "" { target *-*-* } callee_2 }
39 /* { dg-begin-multiline-output "" }
40 extern int callee_2 (int, const char *, float);
41 ^~~~~~~~~~~~
42 { dg-end-multiline-output "" } */
43 }
44
45 /* defn, with argname. */
46
47 static int callee_3 (int one, const char *two, float three) // { dg-line callee_3 }
48 {
49 return callee_2 (one, two, three);
50 }
51
52 int test_3 (int first, int second, float third)
53 {
54 return callee_3 (first, second, third); // { dg-error "invalid conversion from 'int' to 'const char\\*'" }
55 /* { dg-begin-multiline-output "" }
56 return callee_3 (first, second, third);
57 ^~~~~~
58 |
59 int
60 { dg-end-multiline-output "" } */
61 // { dg-message "initializing argument 2 of 'int callee_3\\(int, const char\\*, float\\)'" "" { target *-*-* } callee_3 }
62 /* { dg-begin-multiline-output "" }
63 static int callee_3 (int one, const char *two, float three)
64 ~~~~~~~~~~~~^~~
65 { dg-end-multiline-output "" } */
66 }
67
68 /* static member, with argname. */
69
70 struct s4 { static int member_1 (int one, const char *two, float three); };
71
72 int test_4 (int first, int second, float third)
73 {
74 return s4::member_1 (first, second, third); // { dg-error "invalid conversion from 'int' to 'const char\\*'" }
75 /* { dg-begin-multiline-output "" }
76 return s4::member_1 (first, second, third);
77 ^~~~~~
78 |
79 int
80 { dg-end-multiline-output "" } */
81 /* { dg-begin-multiline-output "" }
82 struct s4 { static int member_1 (int one, const char *two, float three); };
83 ~~~~~~~~~~~~^~~
84 { dg-end-multiline-output "" } */
85 }
86
87 /* non-static member, with argname. */
88
89 struct s5 { int member_1 (int one, const char *two, float three); };
90
91 int test_5 (int first, int second, float third)
92 {
93 s5 inst;
94 return inst.member_1 (first, second, third); // { dg-error "invalid conversion from 'int' to 'const char\\*'" }
95 /* { dg-begin-multiline-output "" }
96 return inst.member_1 (first, second, third);
97 ^~~~~~
98 |
99 int
100 { dg-end-multiline-output "" } */
101 /* { dg-begin-multiline-output "" }
102 struct s5 { int member_1 (int one, const char *two, float three); };
103 ~~~~~~~~~~~~^~~
104 { dg-end-multiline-output "" } */
105 }
106
107 /* non-static member, with argname, via a ptr. */
108
109 struct s6 { int member_1 (int one, const char *two, float three); };
110
111 int test_6 (int first, int second, float third, s6 *ptr)
112 {
113 return ptr->member_1 (first, second, third); // { dg-error "invalid conversion from 'int' to 'const char\\*'" }
114 /* { dg-begin-multiline-output "" }
115 return ptr->member_1 (first, second, third);
116 ^~~~~~
117 |
118 int
119 { dg-end-multiline-output "" } */
120 /* { dg-begin-multiline-output "" }
121 struct s6 { int member_1 (int one, const char *two, float three); };
122 ~~~~~~~~~~~~^~~
123 { dg-end-multiline-output "" } */
124 }
125
126 /* Template function. */
127
128 template <typename T>
129 int test_7 (int one, T two, float three);
130
131 int test_7 (int first, int second, float third)
132 {
133 return test_7 <const char *> (first, second, third); // { dg-error "no matching function" }
134 /* { dg-begin-multiline-output "" }
135 return test_7 <const char *> (first, second, third);
136 ^
137 { dg-end-multiline-output "" } */
138 /* { dg-begin-multiline-output "" }
139 return test_7 <const char *> (first, second, third);
140 ^~~~~~
141 { dg-end-multiline-output "" } */
142 /* { dg-begin-multiline-output "" }
143 int test_7 (int one, T two, float three);
144 ^~~~~~
145 { dg-end-multiline-output "" } */
146 }
147
148 /* Template class, static function. */
149
150 template <typename T>
151 struct s8 { static int member_1 (int one, T two, float three); };
152
153 int test_8 (int first, int second, float third)
154 {
155 return s8 <const char *>::member_1 (first, second, third); // { dg-error "invalid conversion from 'int' to 'const char\\*'" }
156 /* { dg-begin-multiline-output "" }
157 return s8 <const char *>::member_1 (first, second, third);
158 ^~~~~~
159 |
160 int
161 { dg-end-multiline-output "" } */
162 /* { dg-begin-multiline-output "" }
163 struct s8 { static int member_1 (int one, T two, float three); };
164 ~~^~~
165 { dg-end-multiline-output "" } */
166 }
167
168 /* Template class, non-static function. */
169
170 template <typename T>
171 struct s9 { int member_1 (int one, T two, float three); };
172
173 int test_9 (int first, int second, float third)
174 {
175 s9 <const char *> inst;
176 return inst.member_1 (first, second, third); // { dg-error "invalid conversion from 'int' to 'const char\\*'" }
177 /* { dg-begin-multiline-output "" }
178 return inst.member_1 (first, second, third);
179 ^~~~~~
180 |
181 int
182 { dg-end-multiline-output "" } */
183 /* { dg-begin-multiline-output "" }
184 struct s9 { int member_1 (int one, T two, float three); };
185 ~~^~~
186 { dg-end-multiline-output "" } */
187 }
188
189 /* Callback with name. */
190
191 extern int callee_10 (int one, int (*two)(int, int), float three); // { dg-line callee_10 }
192
193 int test_10 (int first, int second, float third)
194 {
195 return callee_10 (first, second, third); // { dg-error "invalid conversion from 'int' to 'int \\(\\*\\)\\(int, int\\)'" }
196 /* { dg-begin-multiline-output "" }
197 return callee_10 (first, second, third);
198 ^~~~~~
199 |
200 int
201 { dg-end-multiline-output "" } */
202 // { dg-message "initializing argument 2 of 'int callee_10\\(int, int \\(\\*\\)\\(int, int\\), float\\)'" "" { target *-*-* } callee_10 }
203 /* { dg-begin-multiline-output "" }
204 extern int callee_10 (int one, int (*two)(int, int), float three);
205 ~~~~~~^~~~~~~~~~~~~~
206 { dg-end-multiline-output "" } */
207 }
208
209 /* Callback without name. */
210
211 extern int callee_11 (int one, int (*)(int, int), float three); // { dg-line callee_11 }
212
213 int test_11 (int first, int second, float third)
214 {
215 return callee_11 (first, second, third); // { dg-error "invalid conversion from 'int' to 'int \\(\\*\\)\\(int, int\\)'" }
216 /* { dg-begin-multiline-output "" }
217 return callee_11 (first, second, third);
218 ^~~~~~
219 |
220 int
221 { dg-end-multiline-output "" } */
222 // { dg-message "initializing argument 2 of 'int callee_11\\(int, int \\(\\*\\)\\(int, int\\), float\\)'" "" { target *-*-* } callee_11 }
223 /* { dg-begin-multiline-output "" }
224 extern int callee_11 (int one, int (*)(int, int), float three);
225 ^~~~~~~~~~~~~~~~~
226 { dg-end-multiline-output "" } */
227 }
228
229 // TODO: template callsite