| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s |
| 2 |
|
| 3 |
// C++03 requires that we check for a copy constructor when binding a |
| 4 |
// reference to a reference-compatible rvalue, since we are allowed to |
| 5 |
// make a copy. C++0x does not permit the copy, so ensure that we |
| 6 |
// don't diagnose cases where the copy constructor is unavailable. |
| 7 |
|
| 8 |
struct X1 { |
| 9 |
X1(); |
| 10 |
explicit X1(const X1&); |
| 11 |
}; |
| 12 |
|
| 13 |
struct X2 { |
| 14 |
X2(); |
| 15 |
|
| 16 |
private: |
| 17 |
X2(const X2&); |
| 18 |
}; |
| 19 |
|
| 20 |
struct X3 { |
| 21 |
X3(); |
| 22 |
|
| 23 |
private: |
| 24 |
X3(X3&); |
| 25 |
}; |
| 26 |
|
| 27 |
template<typename T> |
| 28 |
T get_value_badly() { |
| 29 |
double *dp = 0; |
| 30 |
T *tp = dp; |
| 31 |
return T(); |
| 32 |
} |
| 33 |
|
| 34 |
template<typename T> |
| 35 |
struct X4 { |
| 36 |
X4(); |
| 37 |
X4(const X4&, T = get_value_badly<T>()); |
| 38 |
}; |
| 39 |
|
| 40 |
struct X5 { |
| 41 |
X5(); |
| 42 |
X5(const X5&, const X5& = X5()); |
| 43 |
}; |
| 44 |
|
| 45 |
void g1(const X1&); |
| 46 |
void g2(const X2&); |
| 47 |
void g3(const X3&); |
| 48 |
void g4(const X4<int>&); |
| 49 |
void g5(const X5&); |
| 50 |
|
| 51 |
void test() { |
| 52 |
g1(X1()); |
| 53 |
g2(X2()); |
| 54 |
g3(X3()); |
| 55 |
g4(X4<int>()); |
| 56 |
g5(X5()); |
| 57 |
} |
| 58 |
|
| 59 |
// Check that unavailable copy constructors do not cause SFINAE failures. |
| 60 |
template<int> struct int_c { }; |
| 61 |
|
| 62 |
template<typename T> T f(const T&); |
| 63 |
|
| 64 |
template<typename T> |
| 65 |
int &g(int_c<sizeof(f(T()))> * = 0); // expected-note{{candidate function [with T = X3]}} |
| 66 |
|
| 67 |
template<typename T> float &g(); // expected-note{{candidate function [with T = X3]}} |
| 68 |
|
| 69 |
void h() { |
| 70 |
float &fp = g<X3>(); // expected-error{{call to 'g' is ambiguous}} |
| 71 |
} |