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