• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>
get_value_badly()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 void g1(const X1&);
41 void g2(const X2&);
42 void g3(const X3&);
43 void g4(const X4<int>&);
44 
test()45 void test() {
46   g1(X1());
47   g2(X2());
48   g3(X3());
49   g4(X4<int>());
50 }
51 
52 // Check that unavailable copy constructors do not cause SFINAE failures.
53 template<int> struct int_c { };
54 
55 template<typename T> T f(const T&);
56 
57 template<typename T>
58 int &g(int_c<sizeof(f(T()))> * = 0);  // expected-note{{candidate function [with T = X3]}}
59 
60 template<typename T> float &g();  // expected-note{{candidate function [with T = X3]}}
61 
h()62 void h() {
63   float &fp = g<X3>();  // expected-error{{call to 'g' is ambiguous}}
64 }
65