blob: e7820bb44f09d7e414070168ec9fa1b219517479 [file] [log] [blame]
Fariborz Jahaniand8417782009-08-28 16:23:54 +00001// 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
7extern "C" int printf(...);
Anders Carlsson293361a2009-08-25 13:14:46 +00008struct S {
9 operator int();
10};
11
Anders Carlsson293361a2009-08-25 13:14:46 +000012S::operator int() {
13 return 10;
14}
Fariborz Jahaniand8417782009-08-28 16:23:54 +000015
16
17class 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
25X x;
26
27struct 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
34Z z;
35
36class Y { // ...
37 public: operator Z(){printf("perator Z()\n"); return z; }
38};
39
40Y y;
41
Fariborz Jahanian383d2982009-08-29 20:33:32 +000042int count=0;
43class O { // ...
44public:
45 operator int(){ return ++iO; }
46 O() : iO(count++) {}
47 int iO;
48};
49
50void g(O a, O b)
51{
52 int i = (a) ? 1+a : 0;
53 int j = (a&&b) ? a+b : i;
54 if (a) { }
55 printf("i = %d j = %d a.iO = %d b.iO = %d\n", i, j, a.iO, b.iO);
56}
57
Fariborz Jahaniand8417782009-08-28 16:23:54 +000058int main() {
59 int c = X(Z(y)); // OK: y.operator Z().operator X().operator int()
60 printf("c = %d\n", c);
61 float f = X(Z(y));
62 printf("f = %f\n", f);
63 int i = x;
64 printf("i = %d float = %f\n", i, float(x));
65 i = int(X(Z(y)));
66 f = float(X(Z(y)));
67 printf("i = %d float = %f\n", i,f);
Fariborz Jahanian31976592009-08-29 19:15:16 +000068 f = (float)x;
69 i = (int)x;
70 printf("i = %d float = %f\n", i,f);
71
72 int d = (X)((Z)y);
73 printf("d = %d\n", d);
74
75 int e = (int)((X)((Z)y));
76 printf("e = %d\n", e);
Fariborz Jahanian383d2982009-08-29 20:33:32 +000077 O o1, o2;
78 g(o1, o2);
Fariborz Jahaniand8417782009-08-28 16:23:54 +000079}
80// CHECK-LP64: .globl __ZN1ScviEv
81// CHECK-LP64-NEXT: __ZN1ScviEv:
82// CHECK-LP64: call __ZN1Ycv1ZEv
83// CHECK-LP64: call __ZN1Zcv1XEv
84// CHECK-LP64: call __ZN1XcviEv
85// CHECK-LP64: call __ZN1XcvfEv
86
87// CHECK-LP32: .globl __ZN1ScviEv
88// CHECK-LP32-NEXT: __ZN1ScviEv:
89// CHECK-LP32: call L__ZN1Ycv1ZEv
90// CHECK-LP32: call L__ZN1Zcv1XEv
91// CHECK-LP32: call L__ZN1XcviEv
92// CHECK-LP32: call L__ZN1XcvfEv