Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 2 | void f(int i); |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 3 | void f(int i = 0); // expected-note {{previous definition is here}} |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 4 | void f(int i = 17); // expected-error {{redefinition of default argument}} |
| 5 | |
| 6 | |
| 7 | void g(int i, int j, int k = 3); |
| 8 | void g(int i, int j = 2, int k); |
| 9 | void g(int i = 1, int j, int k); |
| 10 | |
| 11 | void h(int i, int j = 2, int k = 3, |
| 12 | int l, // expected-error {{missing default argument on parameter 'l'}} |
| 13 | int, // expected-error {{missing default argument on parameter}} |
| 14 | int n);// expected-error {{missing default argument on parameter 'n'}} |
| 15 | |
| 16 | struct S { } s; |
Douglas Gregor | a41a8c5 | 2010-04-22 00:20:18 +0000 | [diff] [blame] | 17 | void i(int = s) { } // expected-error {{no viable conversion}} \ |
| 18 | // expected-note{{passing argument to parameter here}} |
Douglas Gregor | eb704f2 | 2008-11-04 13:57:51 +0000 | [diff] [blame] | 19 | |
| 20 | struct X { |
| 21 | X(int); |
| 22 | }; |
| 23 | |
| 24 | void j(X x = 17); |
| 25 | |
Douglas Gregor | 7abfbdb | 2009-12-19 03:01:41 +0000 | [diff] [blame] | 26 | struct Y { // expected-note 2{{candidate}} |
Douglas Gregor | eb704f2 | 2008-11-04 13:57:51 +0000 | [diff] [blame] | 27 | explicit Y(int); |
| 28 | }; |
| 29 | |
Douglas Gregor | a41a8c5 | 2010-04-22 00:20:18 +0000 | [diff] [blame] | 30 | void k(Y y = 17); // expected-error{{no viable conversion}} \ |
| 31 | // expected-note{{passing argument to parameter 'y' here}} |
Douglas Gregor | 61366e9 | 2008-12-24 00:01:03 +0000 | [diff] [blame] | 32 | |
Douglas Gregor | a41a8c5 | 2010-04-22 00:20:18 +0000 | [diff] [blame] | 33 | void kk(Y = 17); // expected-error{{no viable conversion}} \ |
| 34 | // expected-note{{passing argument to parameter here}} |
James Molloy | 9cda03f | 2012-03-13 08:55:35 +0000 | [diff] [blame] | 35 | |
| 36 | int l () { |
| 37 | int m(int i, int j, int k = 3); |
| 38 | if (1) |
| 39 | { |
| 40 | int m(int i, int j = 2, int k = 4); |
| 41 | m(8); |
| 42 | } |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | int i () { |
| 47 | void j (int f = 4); |
| 48 | { |
| 49 | void j (int f); // expected-note{{'j' declared here}} |
Richard Smith | c608c3c | 2012-05-15 06:21:54 +0000 | [diff] [blame] | 50 | j(); // expected-error{{too few arguments to function call, single argument 'f' was not specified}} |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | int i2() { |
| 55 | void j(int f = 4); // expected-note{{'j' declared here}} |
| 56 | { |
| 57 | j(2, 3); // expected-error{{too many arguments to function call, expected at most single argument 'f', have 2}} |
James Molloy | 9cda03f | 2012-03-13 08:55:35 +0000 | [diff] [blame] | 58 | } |
| 59 | } |