derived-to-base-conv.cpp revision a5728872c7702ddd09537c95bc3cbd20e1f2fb09
1// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++0x -S %s -o %t-64.s 2// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s 3// RUN: %clang_cc1 -triple i386-apple-darwin -std=c++0x -S %s -o %t-32.s 4// RUN: FileCheck -check-prefix LP32 --input-file=%t-32.s %s 5 6extern "C" int printf(...); 7extern "C" void exit(int); 8 9struct A { 10 A (const A&) { printf("A::A(const A&)\n"); } 11 A() {}; 12}; 13 14struct B : public A { 15 B() {}; 16}; 17 18struct C : public B { 19 C() {}; 20}; 21 22struct X { 23 operator B&() {printf("X::operator B&()\n"); return b; } 24 operator C&() {printf("X::operator C&()\n"); return c; } 25 X (const X&) { printf("X::X(const X&)\n"); } 26 X () { printf("X::X()\n"); } 27 B b; 28 C c; 29}; 30 31void f(A) { 32 printf("f(A)\n"); 33} 34 35 36void func(X x) 37{ 38 f (x); 39} 40 41int main() 42{ 43 X x; 44 func(x); 45} 46 47struct Base; 48 49struct Root { 50 operator Base&() { exit(1); } 51}; 52 53struct Derived; 54 55struct Base : Root { 56 Base(const Base&) { printf("Base::(const Base&)\n"); } 57 Base() { printf("Base::Base()\n"); } 58 operator Derived&() { exit(1); } 59}; 60 61struct Derived : Base { 62}; 63 64void foo(Base) {} 65 66void test(Derived bb) 67{ 68 // CHECK-LP64-NOT: call __ZN4BasecvR7DerivedEv 69 // CHECK-LP32-NOT: call L__ZN4BasecvR7DerivedEv 70 foo(bb); 71} 72// CHECK-LP64: call __ZN1XcvR1BEv 73// CHECK-LP64: call __ZN1AC1ERKS_ 74 75// CHECK-LP32: call L__ZN1XcvR1BEv 76// CHECK-LP32: call L__ZN1AC1ERKS_ 77 78 79