101 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify=expected,precxx17 %std_cxx98-14 %s2// RUN: %clang_cc1 -fsyntax-only -verify=expected %std_cxx17- %s3struct X {4 operator bool();5};6 7int& f(bool);8float& f(int);9 10void f_test(X x) {11 int& i1 = f(x);12}13 14struct Y {15 operator short();16 operator float();17};18 19void g(int);20 21void g_test(Y y) {22 g(y);23 short s;24 s = y;25}26 27struct A { };28struct B : A { };29 30struct C {31 operator B&();32};33 34// Test reference binding via an lvalue conversion function.35void h(volatile A&);36void h_test(C c) {37 h(c);38}39 40// Test conversion followed by copy-construction41struct FunkyDerived;42 43struct Base { 44 Base(const FunkyDerived&);45};46 47struct Derived : Base { };48 49struct FunkyDerived : Base { };50 51struct ConvertibleToBase {52 operator Base();53};54 55struct ConvertibleToDerived {56 operator Derived();57};58 59struct ConvertibleToFunkyDerived {60 operator FunkyDerived();61};62 63void test_conversion(ConvertibleToBase ctb, ConvertibleToDerived ctd,64 ConvertibleToFunkyDerived ctfd) {65 Base b1 = ctb;66 Base b2(ctb);67 Base b3 = ctd;68 Base b4(ctd);69 Base b5 = ctfd;70}71 72struct X1 {73 X1(X1&); // precxx17-note{{candidate constructor not viable: expects an lvalue for 1st argument}}74};75 76struct X2 {77 operator X1();78};79 80int &f(X1);81float &f(...);82 83void g(X2 b) {84 int &ir = f(b); // precxx17-error{{no viable constructor copying parameter of type 'X1'}}85}86 87namespace rdar10202900 {88 class A {89 public:90 A();91 92 private:93 A(int i); // expected-note{{declared private here}}94 };95 96 void testA(A a) {97 int b = 10;98 a = b; // expected-error{{calling a private constructor of class 'rdar10202900::A'}}99 }100}101