[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / SemaCXX / user-defined-conversions.cpp
blob30b98dc9935d8d17b10696a3438812cf61f51829
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 struct X {
3 operator bool();
4 };
6 int& f(bool);
7 float& f(int);
9 void f_test(X x) {
10 int& i1 = f(x);
13 struct Y {
14 operator short();
15 operator float();
18 void g(int);
20 void g_test(Y y) {
21 g(y);
22 short s;
23 s = y;
26 struct A { };
27 struct B : A { };
29 struct C {
30 operator B&();
33 // Test reference binding via an lvalue conversion function.
34 void h(volatile A&);
35 void h_test(C c) {
36 h(c);
39 // Test conversion followed by copy-construction
40 struct FunkyDerived;
42 struct Base {
43 Base(const FunkyDerived&);
46 struct Derived : Base { };
48 struct FunkyDerived : Base { };
50 struct ConvertibleToBase {
51 operator Base();
54 struct ConvertibleToDerived {
55 operator Derived();
58 struct ConvertibleToFunkyDerived {
59 operator FunkyDerived();
62 void 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);
68 Base b5 = ctfd;
71 struct X1 {
72 X1(X1&); // expected-note{{candidate constructor not viable: expects an lvalue for 1st argument}}
75 struct X2 {
76 operator X1();
79 int &f(X1);
80 float &f(...);
82 void g(X2 b) {
83 int &ir = f(b); // expected-error{{no viable constructor copying parameter of type 'X1'}}
86 namespace rdar10202900 {
87 class A {
88 public:
89 A();
91 private:
92 A(int i); // expected-note{{declared private here}}
95 void testA(A a) {
96 int b = 10;
97 a = b; // expected-error{{calling a private constructor of class 'rdar10202900::A'}}