blob: 284a31069288d07e6195654ae7e4fc5fbfe320f2 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregorf1991ea2008-11-07 22:36:19 +00002struct X {
3 operator bool();
4};
5
6int& f(bool);
7float& f(int);
8
9void f_test(X x) {
10 int& i1 = f(x);
11}
12
13struct Y {
14 operator short();
15 operator float();
16};
17
18void g(int);
19
20void g_test(Y y) {
21 g(y);
Douglas Gregorcb9b9772008-11-10 16:14:15 +000022 short s;
23 s = y;
24}
25
26struct A { };
27struct B : A { };
28
29struct C {
30 operator B&();
31};
32
33// Test reference binding via an lvalue conversion function.
34void h(volatile A&);
35void h_test(C c) {
36 h(c);
Douglas Gregorf1991ea2008-11-07 22:36:19 +000037}
Douglas Gregor734d9862009-01-30 23:27:23 +000038
39// Test conversion followed by copy-construction
40struct FunkyDerived;
41
42struct Base {
43 Base(const FunkyDerived&);
44};
45
46struct Derived : Base { };
47
48struct FunkyDerived : Base { };
49
50struct ConvertibleToBase {
51 operator Base();
52};
53
54struct ConvertibleToDerived {
55 operator Derived();
56};
57
58struct ConvertibleToFunkyDerived {
59 operator FunkyDerived();
60};
61
62void test_conversion(ConvertibleToBase ctb, ConvertibleToDerived ctd,
63 ConvertibleToFunkyDerived ctfd) {
64 Base b1 = ctb;
65 Base b2(ctb);
66 Base b3 = ctd;
67 Base b4(ctd);
Douglas Gregor2b1e0032009-02-02 22:11:10 +000068 Base b5 = ctfd;
Douglas Gregor734d9862009-01-30 23:27:23 +000069}
Douglas Gregor3fbaf3e2010-04-17 22:01:05 +000070
71struct X1 {
Kaelyn Uhrain0d3317e2012-06-19 00:37:47 +000072 X1(X1&); // expected-note{{candidate constructor not viable: expects an l-value for 1st argument}}
Douglas Gregor3fbaf3e2010-04-17 22:01:05 +000073};
74
75struct X2 {
76 operator X1();
77};
78
79int &f(X1);
80float &f(...);
81
82void g(X2 b) {
83 int &ir = f(b); // expected-error{{no viable constructor copying parameter of type 'X1'}}
84}
Douglas Gregor13e1bca2011-10-10 22:41:00 +000085
86namespace rdar10202900 {
87 class A {
88 public:
89 A();
90
91 private:
92 A(int i); // expected-note{{declared private here}}
93 };
94
95 void testA(A a) {
96 int b = 10;
97 a = b; // expected-error{{calling a private constructor of class 'rdar10202900::A'}}
98 }
99}