1 // RUN: %clang_cc1 -fsyntax-only -std=c++03 -Wbind-to-temporary-copy -verify %s
3 // C++03 requires that we check for a copy constructor when binding a
4 // reference to a temporary, since we are allowed to make a copy, Even
5 // though we don't actually make that copy, make sure that we diagnose
6 // cases where that copy constructor is somehow unavailable. As an
7 // extension, this is only a warning.
11 explicit X1(const X1
&);
18 X2(const X2
&); // expected-note{{declared private here}}
22 X3(); // expected-note{{requires 0 arguments, but 1 was provided}}
25 X3(X3
&); // expected-note{{candidate constructor not viable: expects an lvalue for 1st argument}}
28 // Check for instantiation of default arguments
32 // The extension doesn't extend far enough to turn this error into a warning.
33 T
*tp
= dp
; // expected-error{{cannot initialize a variable of type 'int *' with an lvalue of type 'double *'}}
40 X4(const X4
&, T
= get_value_badly
<T
>()); // expected-note{{in instantiation of}}
43 // Check for "dangerous" default arguments that could cause recursion.
46 X5(const X5
&, const X5
& = X5()); // expected-error {{recursive evaluation of default argument}} expected-note {{used here}}
52 void g4(const X4
<int>&);
57 g2(X2()); // expected-warning{{C++98 requires an accessible copy constructor for class 'X2' when binding a reference to a temporary; was private}}
58 g3(X3()); // expected-warning{{no viable constructor copying parameter of type 'X3'}}
63 // Check that unavailable copy constructors still cause SFINAE failures.
64 template<int> struct int_c
{ };
66 template<typename T
> T
f(const T
&);
68 // Would be ambiguous with the next g(), except the instantiation failure in
69 // sizeof() prevents that.
71 int &g(int_c
<sizeof(f(T()))> * = 0);
73 template<typename T
> float &g();
76 float &fp2
= g
<X3
>(); // Not ambiguous.