Anders Carlsson | 9351c17 | 2009-08-25 03:18:48 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s |
| 2 | |
| 3 | struct S { }; |
| 4 | |
| 5 | template<typename T> void f1(T a, T b = 10) { } // expected-error{{cannot initialize 'b' with an rvalue of type 'int'}} |
| 6 | |
| 7 | template<typename T> void f2(T a, T b = T()) { } |
| 8 | |
| 9 | template<typename T> void f3(T a, T b = T() + T()); // expected-error{{invalid operands to binary expression ('struct S' and 'struct S')}} |
| 10 | |
| 11 | void g() { |
| 12 | f1(10); |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 13 | f1(S()); // expected-note{{in instantiation of default function argument expression for 'f1<struct S>' required here}} |
Anders Carlsson | 9351c17 | 2009-08-25 03:18:48 +0000 | [diff] [blame] | 14 | |
| 15 | f2(10); |
| 16 | f2(S()); |
| 17 | |
| 18 | f3(10); |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 19 | f3(S()); // expected-note{{in instantiation of default function argument expression for 'f3<struct S>' required here}} |
Anders Carlsson | 9351c17 | 2009-08-25 03:18:48 +0000 | [diff] [blame] | 20 | } |
Anders Carlsson | 8644aec | 2009-08-25 13:07:08 +0000 | [diff] [blame] | 21 | |
| 22 | template<typename T> struct F { |
Anders Carlsson | 21e1c4e | 2009-09-06 16:54:02 +0000 | [diff] [blame] | 23 | F(T t = 10); // expected-error{{cannot initialize 't' with an rvalue of type 'int'}} |
Anders Carlsson | 6bc107b | 2009-09-05 05:38:54 +0000 | [diff] [blame] | 24 | void f(T t = 10); // expected-error{{cannot initialize 't' with an rvalue of type 'int'}} |
Anders Carlsson | 8644aec | 2009-08-25 13:07:08 +0000 | [diff] [blame] | 25 | }; |
| 26 | |
Douglas Gregor | 0b84a53 | 2009-08-25 15:24:38 +0000 | [diff] [blame] | 27 | struct FD : F<int> { }; |
| 28 | |
Anders Carlsson | 8644aec | 2009-08-25 13:07:08 +0000 | [diff] [blame] | 29 | void g2() { |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 30 | F<int> f; |
Douglas Gregor | 0b84a53 | 2009-08-25 15:24:38 +0000 | [diff] [blame] | 31 | FD fd; |
Anders Carlsson | 8644aec | 2009-08-25 13:07:08 +0000 | [diff] [blame] | 32 | } |
Anders Carlsson | 5653ca5 | 2009-08-25 13:46:13 +0000 | [diff] [blame] | 33 | |
Anders Carlsson | 6bc107b | 2009-09-05 05:38:54 +0000 | [diff] [blame] | 34 | void g3(F<int> f, F<struct S> s) { |
| 35 | f.f(); |
| 36 | s.f(); // expected-note{{in instantiation of default function argument expression for 'f<struct S>' required here}} |
Anders Carlsson | 21e1c4e | 2009-09-06 16:54:02 +0000 | [diff] [blame] | 37 | |
| 38 | F<int> f2; |
| 39 | F<S> s2; // expected-note{{in instantiation of default function argument expression for 'F<struct S>' required here}} |
Anders Carlsson | 6bc107b | 2009-09-05 05:38:54 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Anders Carlsson | 5653ca5 | 2009-08-25 13:46:13 +0000 | [diff] [blame] | 42 | template<typename T> struct G { |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 43 | G(T) {} |
Anders Carlsson | 5653ca5 | 2009-08-25 13:46:13 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | void s(G<int> flags = 10) { } |
| 47 | |
Douglas Gregor | 6cc1518 | 2009-09-11 18:44:32 +0000 | [diff] [blame^] | 48 | // Test default arguments |
| 49 | template<typename T> |
| 50 | struct X0 { |
| 51 | void f(T = T()); // expected-error{{no matching}} |
| 52 | }; |
Anders Carlsson | 5653ca5 | 2009-08-25 13:46:13 +0000 | [diff] [blame] | 53 | |
Douglas Gregor | 6cc1518 | 2009-09-11 18:44:32 +0000 | [diff] [blame^] | 54 | template<typename U> |
| 55 | void X0<U>::f(U) { } |
Anders Carlsson | 6bc107b | 2009-09-05 05:38:54 +0000 | [diff] [blame] | 56 | |
Douglas Gregor | 6cc1518 | 2009-09-11 18:44:32 +0000 | [diff] [blame^] | 57 | void test_x0(X0<int> xi) { |
| 58 | xi.f(); |
| 59 | xi.f(17); |
| 60 | } |
| 61 | |
| 62 | struct NotDefaultConstructible { // expected-note{{candidate}} |
| 63 | NotDefaultConstructible(int); // expected-note{{candidate}} |
| 64 | }; |
| 65 | |
| 66 | void test_x0_not_default_constructible(X0<NotDefaultConstructible> xn) { |
| 67 | xn.f(NotDefaultConstructible(17)); |
| 68 | xn.f(42); |
| 69 | xn.f(); // expected-note{{in instantiation of default function argument}} |
| 70 | } |