C++: special-case single non-viable candidate (more PR c++/85110)
[official-gcc.git] / gcc / testsuite / g++.dg / diagnostic / param-type-mismatch-2.C
blobf74f8d39e26f7e4616ad89346319d10f5eb7a900
1 // { dg-options "-fdiagnostics-show-caret" }
3 /* A collection of calls where argument 2 is of the wrong type.  */
5 /* decl, with argname.  */
7 extern int callee_1 (int one, const char **two, float three); // { dg-line callee_1 }
9 int test_1 (int first, const char *second, float third)
11   return callee_1 (first, second, third); // { dg-error "27: cannot convert 'const char\\*' to 'const char\\*\\*'" }
12   /* { dg-begin-multiline-output "" }
13    return callee_1 (first, second, third);
14                            ^~~~~~
15                            |
16                            const char*
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 "" } */
25 /* decl, without argname.  */
27 extern int callee_2 (int, const char **, float); // { dg-line callee_2 }
29 int test_2 (int first, const char *second, float third)
31   return callee_2 (first, second, third); // { dg-error "27: cannot convert 'const char\\*' to 'const char\\*\\*'" }
32   /* { dg-begin-multiline-output "" }
33    return callee_2 (first, second, third);
34                            ^~~~~~
35                            |
36                            const char*
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 "" } */
45 /* defn, with argname.  */
47 static int callee_3 (int one, const char **two, float three) // { dg-line callee_3 }
49   return callee_2 (one, two, three);
52 int test_3 (int first, const char *second, float third)
54   return callee_3 (first, second, third); // { dg-error "27: cannot convert 'const char\\*' to 'const char\\*\\*'" }
55   /* { dg-begin-multiline-output "" }
56    return callee_3 (first, second, third);
57                            ^~~~~~
58                            |
59                            const char*
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 "" } */
68 /* static member, with argname.  */
70 struct s4 { static int member_1 (int one, const char **two, float three); }; // { dg-line s4_member_1 }
72 int test_4 (int first, const char *second, float third)
74   return s4::member_1 (first, second, third); // { dg-error "31: cannot convert 'const char\\*' to 'const char\\*\\*'" }
75   /* { dg-begin-multiline-output "" }
76    return s4::member_1 (first, second, third);
77                                ^~~~~~
78                                |
79                                const char*
80      { dg-end-multiline-output "" } */
81   // { dg-message "initializing argument 2 of 'static int s4::member_1\\(int, const char\\*\\*, float\\)'" "" { target *-*-* } s4_member_1 } 
82   /* { dg-begin-multiline-output "" } 
83  struct s4 { static int member_1 (int one, const char **two, float three); };
84                                            ~~~~~~~~~~~~~^~~
85      { dg-end-multiline-output "" } */
88 /* non-static member, with argname.  */
90 struct s5 { int member_1 (int one, const char **two, float three); }; // { dg-line s5_member_1 }
92 int test_5 (int first, const char *second, float third)
94   s5 inst;
95   return inst.member_1 (first, second, third); // { dg-error "32: cannot convert 'const char\\*' to 'const char\\*\\*'" }
96   /* { dg-begin-multiline-output "" }
97    return inst.member_1 (first, second, third);
98                                 ^~~~~~
99                                 |
100                                 const char*
101      { dg-end-multiline-output "" } */
102   // { dg-message "initializing argument 2 of 'int s5::member_1\\(int, const char\\*\\*, float\\)'" "" { target *-*-* } s5_member_1 } 
103   /* { dg-begin-multiline-output "" }
104  struct s5 { int member_1 (int one, const char **two, float three); };
105                                     ~~~~~~~~~~~~~^~~
106      { dg-end-multiline-output "" } */
109 /* non-static member, with argname, via a ptr.  */
111 struct s6 { int member_1 (int one, const char **two, float three); }; // { dg-line s6_member_1 }
113 int test_6 (int first, const char *second, float third, s6 *ptr)
115   return ptr->member_1 (first, second, third); // { dg-error "32: cannot convert 'const char\\*' to 'const char\\*\\*'" }
116   /* { dg-begin-multiline-output "" }
117    return ptr->member_1 (first, second, third);
118                                 ^~~~~~
119                                 |
120                                 const char*
121      { dg-end-multiline-output "" } */
122   // { dg-message "initializing argument 2 of 'int s6::member_1\\(int, const char\\*\\*, float\\)'" "" { target *-*-* } s6_member_1 } 
123   /* { dg-begin-multiline-output "" } 
124  struct s6 { int member_1 (int one, const char **two, float three); };
125                                     ~~~~~~~~~~~~~^~~
126      { dg-end-multiline-output "" } */
129 /* Template function.  */
131 template <typename T>
132 int test_7 (int one, T two, float three); // { dg-line test_7_decl }
134 int test_7 (int first, const char *second, float third)
136   return test_7 <const char **> (first, second, third); // { dg-line test_7_usage }
137   // { dg-error "no matching function" "" { target *-*-* } test_7_usage }
138   /* { dg-begin-multiline-output "" }
139    return test_7 <const char **> (first, second, third);
140                                                       ^
141      { dg-end-multiline-output "" } */
142   // { dg-message "candidate: 'template<class T> int test_7\\(int, T, float\\)'" "" { target *-*-* } test_7_decl }
143   /* { dg-begin-multiline-output "" }
144  int test_7 (int one, T two, float three);
145      ^~~~~~
146      { dg-end-multiline-output "" } */
147   // { dg-message "template argument deduction/substitution failed:" "" { target *-*-* } test_7_decl }
148   // { dg-message "cannot convert 'second' \\(type 'const char\\*'\\) to type 'const char\\*\\*'" "" { target *-*-* } test_7_usage }
149   /* { dg-begin-multiline-output "" }
150    return test_7 <const char **> (first, second, third);
151                                          ^~~~~~
152      { dg-end-multiline-output "" } */
155 /* Template class, static function.  */
157 template <typename T>
158 struct s8 { static int member_1 (int one, T two, float three); }; // { dg-line s8_member_1 }
160 int test_8 (int first, const char *second, float third)
162   return s8 <const char **>::member_1 (first, second, third); // { dg-error "47: cannot convert 'const char\\*' to 'const char\\*\\*'" }
163   /* { dg-begin-multiline-output "" }
164    return s8 <const char **>::member_1 (first, second, third);
165                                                ^~~~~~
166                                                |
167                                                const char*
168      { dg-end-multiline-output "" } */
169   // { dg-message "initializing argument 2 of 'static int s8<T>::member_1\\(int, T, float\\) .with T = const char\\*\\*.'" "" { target *-*-* } s8_member_1 } 
170   /* { dg-begin-multiline-output "" }
171  struct s8 { static int member_1 (int one, T two, float three); };
172                                            ~~^~~
173      { dg-end-multiline-output "" } */
176 /* Template class, non-static function.  */
178 template <typename T>
179 struct s9 { int member_1 (int one, T two, float three); }; // { dg-line s9_member_1 }
181 int test_9 (int first, const char *second, float third)
183   s9 <const char **> inst;
184   return inst.member_1 (first, second, third); // { dg-error "32: cannot convert 'const char\\*' to 'const char\\*\\*'" }
185   /* { dg-begin-multiline-output "" }
186    return inst.member_1 (first, second, third);
187                                 ^~~~~~
188                                 |
189                                 const char*
190      { dg-end-multiline-output "" } */
191   // { dg-message "initializing argument 2 of 'int s9<T>::member_1\\(int, T, float\\) .with T = const char\\*\\*.'" "" { target *-*-* } s9_member_1 } 
192   /* { dg-begin-multiline-output "" }
193  struct s9 { int member_1 (int one, T two, float three); };
194                                     ~~^~~
195      { dg-end-multiline-output "" } */
198 /* Overloaded operator (with one candidate).  */
200 struct s10 {};
202 extern int operator- (const s10&, int); // { dg-line s10_operator }
204 int test_10 ()
206   s10 v10_a, v10_b;
208   return v10_a - v10_b; // { dg-error "no match for" }
209   /* { dg-begin-multiline-output "" }
210    return v10_a - v10_b;
211           ~~~~~~^~~~~~~
212      { dg-end-multiline-output "" } */
213   // { dg-message "candidate" "" { target *-*-* } s10_operator }
214   /* { dg-begin-multiline-output "" }
215  extern int operator- (const s10&, int);
216             ^~~~~~~~
217      { dg-end-multiline-output "" } */
218   // { dg-message "no known conversion for argument 2 from" "" { target *-*-* } s10_operator }
219   /* { dg-begin-multiline-output "" }
220  extern int operator- (const s10&, int);
221                                    ^~~
222      { dg-end-multiline-output "" } */