p5-cxx03-extra-copy.cpp revision 523d46af407f32fc53861e6f068e8076d4fe84a8
1// RUN: %clang_cc1 -fsyntax-only -verify %s
2
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.
7
8struct X1 {
9  X1();
10  explicit X1(const X1&);
11};
12
13struct X2 {
14  X2();
15
16private:
17  X2(const X2&); // expected-note{{declared private here}}
18};
19
20struct X3 {
21  X3();
22
23private:
24  X3(X3&); // expected-note{{candidate constructor not viable: no known conversion from 'X3' to 'X3 &' for 1st argument}}
25};
26
27template<typename T>
28T get_value_badly() {
29  double *dp = 0;
30  T *tp = dp; // FIXME: Should get an error here, from instantiating the
31              // default argument of X4<int>
32  return T();
33}
34
35template<typename T>
36struct X4 {
37  X4();
38  X4(const X4&, T = get_value_badly<T>());
39};
40
41void g1(const X1&);
42void g2(const X2&);
43void g3(const X3&);
44void g4(const X4<int>&);
45
46void test() {
47  g1(X1()); // expected-error{{no viable constructor copying parameter of type 'X1'}}
48  g2(X2()); // expected-error{{calling a private constructor of class 'X2'}}
49  g3(X3()); // expected-error{{no viable constructor copying parameter of type 'X3'}}
50  g4(X4<int>());
51}
52