Fariborz Jahanian | d841778 | 2009-08-28 16:23:54 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -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-cc -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 | // RUN: true |
| 6 | |
| 7 | extern "C" int printf(...); |
Anders Carlsson | 293361a | 2009-08-25 13:14:46 +0000 | [diff] [blame] | 8 | struct S { |
| 9 | operator int(); |
| 10 | }; |
| 11 | |
Anders Carlsson | 293361a | 2009-08-25 13:14:46 +0000 | [diff] [blame] | 12 | S::operator int() { |
| 13 | return 10; |
| 14 | } |
Fariborz Jahanian | d841778 | 2009-08-28 16:23:54 +0000 | [diff] [blame] | 15 | |
| 16 | |
| 17 | class X { // ... |
| 18 | public: operator int() { printf("operator int()\n"); return iX; } |
| 19 | public: operator float() { printf("operator float()\n"); return fX; } |
| 20 | X() : iX(100), fX(1.234) {} |
| 21 | int iX; |
| 22 | float fX; |
| 23 | }; |
| 24 | |
| 25 | X x; |
| 26 | |
| 27 | struct Z { |
| 28 | operator X() { printf("perator X()\n"); x.iX += iZ; x.fX += fZ; return x; } |
| 29 | int iZ; |
| 30 | float fZ; |
| 31 | Z() : iZ(1), fZ(1.00) {} |
| 32 | }; |
| 33 | |
| 34 | Z z; |
| 35 | |
| 36 | class Y { // ... |
| 37 | public: operator Z(){printf("perator Z()\n"); return z; } |
| 38 | }; |
| 39 | |
| 40 | Y y; |
| 41 | |
| 42 | int main() { |
| 43 | int c = X(Z(y)); // OK: y.operator Z().operator X().operator int() |
| 44 | printf("c = %d\n", c); |
| 45 | float f = X(Z(y)); |
| 46 | printf("f = %f\n", f); |
| 47 | int i = x; |
| 48 | printf("i = %d float = %f\n", i, float(x)); |
| 49 | i = int(X(Z(y))); |
| 50 | f = float(X(Z(y))); |
| 51 | printf("i = %d float = %f\n", i,f); |
Fariborz Jahanian | 3197659 | 2009-08-29 19:15:16 +0000 | [diff] [blame^] | 52 | f = (float)x; |
| 53 | i = (int)x; |
| 54 | printf("i = %d float = %f\n", i,f); |
| 55 | |
| 56 | int d = (X)((Z)y); |
| 57 | printf("d = %d\n", d); |
| 58 | |
| 59 | int e = (int)((X)((Z)y)); |
| 60 | printf("e = %d\n", e); |
Fariborz Jahanian | d841778 | 2009-08-28 16:23:54 +0000 | [diff] [blame] | 61 | } |
| 62 | // CHECK-LP64: .globl __ZN1ScviEv |
| 63 | // CHECK-LP64-NEXT: __ZN1ScviEv: |
| 64 | // CHECK-LP64: call __ZN1Ycv1ZEv |
| 65 | // CHECK-LP64: call __ZN1Zcv1XEv |
| 66 | // CHECK-LP64: call __ZN1XcviEv |
| 67 | // CHECK-LP64: call __ZN1XcvfEv |
| 68 | |
| 69 | // CHECK-LP32: .globl __ZN1ScviEv |
| 70 | // CHECK-LP32-NEXT: __ZN1ScviEv: |
| 71 | // CHECK-LP32: call L__ZN1Ycv1ZEv |
| 72 | // CHECK-LP32: call L__ZN1Zcv1XEv |
| 73 | // CHECK-LP32: call L__ZN1XcviEv |
| 74 | // CHECK-LP32: call L__ZN1XcvfEv |