blob: f2835b7a299eef66ccbdbffbf4b204bc84476e0e [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++0x -S %s -o %t-64.s
Daniel Dunbar4fcfde42009-11-08 01:45:36 +00002// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s
Daniel Dunbara5728872009-12-15 20:14:24 +00003// RUN: %clang_cc1 -triple i386-apple-darwin -std=c++0x -S %s -o %t-32.s
Daniel Dunbar4fcfde42009-11-08 01:45:36 +00004// RUN: FileCheck -check-prefix LP32 --input-file=%t-32.s %s
Fariborz Jahanian93034ca2009-10-16 19:20:59 +00005
6extern "C" int printf(...);
Fariborz Jahanian3759a032009-10-19 19:18:20 +00007extern "C" void exit(int);
Fariborz Jahanian93034ca2009-10-16 19:20:59 +00008
9struct A {
Douglas Gregor2f599792010-04-02 18:24:57 +000010 A (const A&) { printf("A::A(const A&)\n"); }
11 A() {};
12 ~A() { printf("A::~A()\n"); }
Fariborz Jahanian93034ca2009-10-16 19:20:59 +000013};
14
15struct B : public A {
16 B() {};
Douglas Gregor2f599792010-04-02 18:24:57 +000017 B(const B& Other) : A(Other) { printf("B::B(const B&)\n"); }
18 ~B() { printf("B::~B()\n"); }
19};
Fariborz Jahanian93034ca2009-10-16 19:20:59 +000020
21struct C : public B {
22 C() {};
Douglas Gregor2f599792010-04-02 18:24:57 +000023 C(const C& Other) : B(Other) { printf("C::C(const C&)\n"); }
24 ~C() { printf("C::~C()\n"); }
Fariborz Jahanian93034ca2009-10-16 19:20:59 +000025};
26
27struct X {
28 operator B&() {printf("X::operator B&()\n"); return b; }
29 operator C&() {printf("X::operator C&()\n"); return c; }
30 X (const X&) { printf("X::X(const X&)\n"); }
31 X () { printf("X::X()\n"); }
Douglas Gregor2f599792010-04-02 18:24:57 +000032 ~X () { printf("X::~X()\n"); }
Fariborz Jahanian93034ca2009-10-16 19:20:59 +000033 B b;
34 C c;
35};
36
37void f(A) {
38 printf("f(A)\n");
39}
40
41
42void func(X x)
43{
44 f (x);
45}
46
47int main()
48{
49 X x;
50 func(x);
51}
52
Fariborz Jahanian3759a032009-10-19 19:18:20 +000053struct Base;
54
55struct Root {
56 operator Base&() { exit(1); }
57};
58
59struct Derived;
60
61struct Base : Root {
62 Base(const Base&) { printf("Base::(const Base&)\n"); }
63 Base() { printf("Base::Base()\n"); }
64 operator Derived&() { exit(1); }
65};
66
67struct Derived : Base {
68};
69
70void foo(Base) {}
71
72void test(Derived bb)
73{
Sean Callanan3b299012009-12-18 00:04:09 +000074 // CHECK-LP64-NOT: callq __ZN4BasecvR7DerivedEv
75 // CHECK-LP32-NOT: callq L__ZN4BasecvR7DerivedEv
Fariborz Jahanian3759a032009-10-19 19:18:20 +000076 foo(bb);
77}
Sean Callanan3b299012009-12-18 00:04:09 +000078// CHECK-LP64: callq __ZN1XcvR1BEv
79// CHECK-LP64: callq __ZN1AC1ERKS_
Fariborz Jahanian93034ca2009-10-16 19:20:59 +000080
81// CHECK-LP32: call L__ZN1XcvR1BEv
82// CHECK-LP32: call L__ZN1AC1ERKS_
Fariborz Jahanian3759a032009-10-19 19:18:20 +000083
84