summaryrefslogtreecommitdiffstats
path: root/test/CodeGenCXX/derived-to-base-conv.cpp
blob: 70948b0ff933c973245749daf0645078423e1e49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// RUN: clang-cc -triple x86_64-apple-darwin -std=c++0x -S %s -o %t-64.s
// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s
// RUN: clang-cc -triple i386-apple-darwin -std=c++0x -S %s -o %t-32.s
// RUN: FileCheck -check-prefix LP32 --input-file=%t-32.s %s

extern "C" int printf(...);
extern "C" void exit(int);

struct A {
 A (const A&) { printf("A::A(const A&)\n"); }
 A() {};
}; 

struct B : public A {
  B() {};
}; 

struct C : public B {
  C() {};
}; 

struct X {
	operator B&() {printf("X::operator B&()\n"); return b; }
	operator C&() {printf("X::operator C&()\n"); return c; }
 	X (const X&) { printf("X::X(const X&)\n"); }
 	X () { printf("X::X()\n"); }
	B b;
	C c;
};

void f(A) {
  printf("f(A)\n");
}


void func(X x) 
{
  f (x);
}

int main()
{
    X x;
    func(x);
}

struct Base;

struct Root {
  operator Base&() { exit(1); }
};

struct Derived;

struct Base : Root {
  Base(const Base&) { printf("Base::(const Base&)\n"); }
  Base() { printf("Base::Base()\n"); }
  operator Derived&() { exit(1); }
};

struct Derived : Base {
};

void foo(Base) {}

void test(Derived bb)
{
	// CHECK-LP64-NOT: call     __ZN4BasecvR7DerivedEv
	// CHECK-LP32-NOT: call     L__ZN4BasecvR7DerivedEv
        foo(bb);
}
// CHECK-LP64: call     __ZN1XcvR1BEv
// CHECK-LP64: call     __ZN1AC1ERKS_

// CHECK-LP32: call     L__ZN1XcvR1BEv
// CHECK-LP32: call     L__ZN1AC1ERKS_