Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 2 | struct X0 { // expected-note{{candidate}} |
| 3 | X0(int); // expected-note{{candidate}} |
| 4 | template<typename T> X0(T); |
| 5 | template<typename T, typename U> X0(T*, U*); |
Douglas Gregor | efd5bda | 2009-08-24 11:57:43 +0000 | [diff] [blame] | 6 | |
| 7 | // PR4761 |
| 8 | template<typename T> X0() : f0(T::foo) {} |
| 9 | int f0; |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 10 | }; |
| 11 | |
| 12 | void accept_X0(X0); |
| 13 | |
| 14 | void test_X0(int i, float f) { |
| 15 | X0 x0a(i); |
| 16 | X0 x0b(f); |
| 17 | X0 x0c = i; |
| 18 | X0 x0d = f; |
| 19 | accept_X0(i); |
| 20 | accept_X0(&i); |
| 21 | accept_X0(f); |
| 22 | accept_X0(&f); |
| 23 | X0 x0e(&i, &f); |
| 24 | X0 x0f(&f, &i); |
| 25 | |
| 26 | X0 x0g(f, &i); // expected-error{{no matching constructor}} |
| 27 | } |
Douglas Gregor | f882574 | 2009-09-15 18:26:13 +0000 | [diff] [blame] | 28 | |
| 29 | template<typename T> |
| 30 | struct X1 { |
| 31 | X1(const X1&); |
| 32 | template<typename U> X1(const X1<U>&); |
| 33 | }; |
| 34 | |
| 35 | template<typename T> |
| 36 | struct Outer { |
| 37 | typedef X1<T> A; |
| 38 | |
| 39 | A alloc; |
| 40 | |
| 41 | explicit Outer(const A& a) : alloc(a) { } |
| 42 | }; |
| 43 | |
| 44 | void test_X1(X1<int> xi) { |
| 45 | Outer<int> oi(xi); |
| 46 | Outer<float> of(xi); |
| 47 | } |
Douglas Gregor | c7e406b | 2009-09-15 21:14:05 +0000 | [diff] [blame] | 48 | |
| 49 | // PR4655 |
| 50 | template<class C> struct A {}; |
| 51 | template <> struct A<int>{A(const A<int>&);}; |
| 52 | struct B { A<int> x; B(B& a) : x(a.x) {} }; |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 53 | |
Douglas Gregor | 66724ea | 2009-11-14 01:20:54 +0000 | [diff] [blame] | 54 | struct X2 { |
| 55 | X2(); |
| 56 | X2(X2&); |
| 57 | template<typename T> X2(T); |
| 58 | }; |
| 59 | |
| 60 | X2 test(bool Cond, X2 x2) { |
| 61 | if (Cond) |
| 62 | return x2; // okay, uses copy constructor |
| 63 | |
| 64 | return X2(); // expected-error{{incompatible type}} |
| 65 | } |
| 66 | |
| 67 | struct X3 { |
| 68 | template<typename T> X3(T); |
| 69 | }; |
| 70 | |
| 71 | template<> X3::X3(X3); // expected-error{{must pass its first argument by reference}} |
| 72 | |
| 73 | struct X4 { |
| 74 | X4(); |
| 75 | ~X4(); |
| 76 | X4(X4&); |
| 77 | template<typename T> X4(const T&, int = 17); |
| 78 | }; |
| 79 | |
| 80 | X4 test_X4(bool Cond, X4 x4) { |
| 81 | X4 a(x4, 17); // okay, constructor template |
| 82 | X4 b(x4); // okay, copy constructor |
| 83 | return X4(); // expected-error{{incompatible type}} |
| 84 | } |