2011-10-14 06:29:44 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -S %s -o %t-64.s
|
2013-08-12 20:51:05 +08:00
|
|
|
// RUN: FileCheck -check-prefix CHECK-LP64 --input-file=%t-64.s %s
|
2011-10-14 06:29:44 +08:00
|
|
|
// RUN: %clang_cc1 -triple i386-apple-darwin -std=c++11 -S %s -o %t-32.s
|
2013-08-12 20:51:05 +08:00
|
|
|
// RUN: FileCheck -check-prefix CHECK-LP32 --input-file=%t-32.s %s
|
2010-01-27 11:06:00 +08:00
|
|
|
// XFAIL: *
|
2009-08-29 00:23:54 +08:00
|
|
|
extern "C" int printf(...);
|
2009-08-25 21:14:46 +08:00
|
|
|
struct S {
|
2009-09-09 23:08:12 +08:00
|
|
|
operator int();
|
2009-08-25 21:14:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
S::operator int() {
|
2009-09-09 23:08:12 +08:00
|
|
|
return 10;
|
2009-08-25 21:14:46 +08:00
|
|
|
}
|
2009-08-29 00:23:54 +08:00
|
|
|
|
2009-12-18 22:42:03 +08:00
|
|
|
int f(S s) {
|
|
|
|
return s;
|
|
|
|
}
|
2009-08-29 00:23:54 +08:00
|
|
|
|
|
|
|
class X { // ...
|
|
|
|
public: operator int() { printf("operator int()\n"); return iX; }
|
|
|
|
public: operator float() { printf("operator float()\n"); return fX; }
|
|
|
|
X() : iX(100), fX(1.234) {}
|
|
|
|
int iX;
|
|
|
|
float fX;
|
|
|
|
};
|
|
|
|
|
|
|
|
X x;
|
|
|
|
|
|
|
|
struct Z {
|
|
|
|
operator X() { printf("perator X()\n"); x.iX += iZ; x.fX += fZ; return x; }
|
|
|
|
int iZ;
|
|
|
|
float fZ;
|
|
|
|
Z() : iZ(1), fZ(1.00) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
Z z;
|
|
|
|
|
|
|
|
class Y { // ...
|
|
|
|
public: operator Z(){printf("perator Z()\n"); return z; }
|
|
|
|
};
|
|
|
|
|
|
|
|
Y y;
|
|
|
|
|
2009-08-30 04:33:32 +08:00
|
|
|
int count=0;
|
|
|
|
class O { // ...
|
|
|
|
public:
|
2009-09-09 23:08:12 +08:00
|
|
|
operator int(){ return ++iO; }
|
|
|
|
O() : iO(count++) {}
|
|
|
|
int iO;
|
2009-08-30 04:33:32 +08:00
|
|
|
};
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
void g(O a, O b) {
|
|
|
|
int i = (a) ? 1+a : 0;
|
|
|
|
int j = (a&&b) ? a+b : i;
|
|
|
|
if (a) { }
|
|
|
|
printf("i = %d j = %d a.iO = %d b.iO = %d\n", i, j, a.iO, b.iO);
|
2009-08-30 04:33:32 +08:00
|
|
|
}
|
|
|
|
|
2009-08-29 00:23:54 +08:00
|
|
|
int main() {
|
2009-09-09 23:08:12 +08:00
|
|
|
int c = X(Z(y)); // OK: y.operator Z().operator X().operator int()
|
|
|
|
printf("c = %d\n", c);
|
|
|
|
float f = X(Z(y));
|
|
|
|
printf("f = %f\n", f);
|
|
|
|
int i = x;
|
|
|
|
printf("i = %d float = %f\n", i, float(x));
|
|
|
|
i = int(X(Z(y)));
|
|
|
|
f = float(X(Z(y)));
|
|
|
|
printf("i = %d float = %f\n", i,f);
|
|
|
|
f = (float)x;
|
|
|
|
i = (int)x;
|
|
|
|
printf("i = %d float = %f\n", i,f);
|
|
|
|
|
|
|
|
int d = (X)((Z)y);
|
|
|
|
printf("d = %d\n", d);
|
|
|
|
|
|
|
|
int e = (int)((X)((Z)y));
|
|
|
|
printf("e = %d\n", e);
|
|
|
|
O o1, o2;
|
|
|
|
g(o1, o2);
|
2009-08-29 00:23:54 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-09-15 04:41:01 +08:00
|
|
|
// Test. Conversion in base class is visible in derived class.
|
|
|
|
class XB {
|
2009-09-15 15:42:44 +08:00
|
|
|
int a;
|
2009-09-15 04:41:01 +08:00
|
|
|
public:
|
|
|
|
operator int();
|
|
|
|
};
|
|
|
|
|
|
|
|
class Yb : public XB {
|
2009-09-15 15:42:44 +08:00
|
|
|
double b;
|
2009-09-15 04:41:01 +08:00
|
|
|
public:
|
|
|
|
operator char();
|
|
|
|
};
|
|
|
|
|
|
|
|
void f(Yb& a) {
|
|
|
|
int i = a; // OK. calls XB::operator int();
|
|
|
|
char ch = a; // OK. calls Yb::operator char();
|
|
|
|
}
|
|
|
|
|
2009-12-18 22:42:03 +08:00
|
|
|
struct A {
|
|
|
|
operator int() const;
|
|
|
|
};
|
2009-09-15 04:41:01 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
// CHECK-LP64: .globl __ZN1ScviEv
|
2009-08-29 00:23:54 +08:00
|
|
|
// CHECK-LP64-NEXT: __ZN1ScviEv:
|
2009-12-18 08:04:09 +08:00
|
|
|
// CHECK-LP64: callq __ZN1Ycv1ZEv
|
|
|
|
// CHECK-LP64: callq __ZN1Zcv1XEv
|
|
|
|
// CHECK-LP64: callq __ZN1XcviEv
|
|
|
|
// CHECK-LP64: callq __ZN1XcvfEv
|
|
|
|
// CHECK-LP64: callq __ZN2XBcviEv
|
|
|
|
// CHECK-LP64: callq __ZN2YbcvcEv
|
2009-08-29 00:23:54 +08:00
|
|
|
|
|
|
|
// CHECK-LP32: .globl __ZN1ScviEv
|
|
|
|
// CHECK-LP32-NEXT: __ZN1ScviEv:
|
2009-09-09 23:08:12 +08:00
|
|
|
// CHECK-LP32: call L__ZN1Ycv1ZEv
|
|
|
|
// CHECK-LP32: call L__ZN1Zcv1XEv
|
|
|
|
// CHECK-LP32: call L__ZN1XcviEv
|
|
|
|
// CHECK-LP32: call L__ZN1XcvfEv
|
2009-09-15 04:41:01 +08:00
|
|
|
// CHECK-LP32: call L__ZN2XBcviEv
|
|
|
|
// CHECK-LP32: call L__ZN2YbcvcEv
|