conversion-function.cpp [plain text]
class X {
public:
operator bool();
operator int() const;
bool f() {
return operator bool();
}
float g() {
return operator float(); }
};
operator int();
operator int;
typedef int func_type(int);
typedef int array_type[10];
class Y {
public:
void operator bool(int, ...) const;
operator float(...) const;
operator func_type(); operator array_type(); };
typedef int INT;
typedef INT* INT_PTR;
class Z {
operator int(); operator int**();
operator INT(); operator INT_PTR*(); };
class A { };
class B : public A {
public:
operator A&() const; operator const void() const; operator const B(); };
struct Flip;
struct Flop {
Flop();
Flop(const Flip&); };
struct Flip {
operator Flop() const; };
Flop flop = Flip();
struct C {
operator const char *() const;
};
C::operator const char*() const { return 0; }
void f(const C& c) {
const char* v = c;
}
class XB {
public:
operator int(); };
class Yb : public XB {
public:
operator char(); };
void f(Yb& a) {
if (a) { } int i = a; char ch = a; }
class AutoPtrRef { };
class AutoPtr {
AutoPtr(AutoPtr &);
public:
AutoPtr();
AutoPtr(AutoPtrRef);
operator AutoPtrRef();
};
AutoPtr make_auto_ptr();
AutoPtr test_auto_ptr(bool Cond) {
AutoPtr p1( make_auto_ptr() );
AutoPtr p;
if (Cond)
return p;
return AutoPtr();
}
struct A1 {
A1(const char *);
~A1();
private:
A1(const A1&); };
A1 f() {
return "Hello"; }
namespace source_locations {
template<typename T>
struct sneaky_int {
typedef int type;
};
template<typename T, typename U>
struct A { };
template<typename T>
struct A<T, T> : A<T, int> { };
struct E {
template<typename T>
operator A<T, typename sneaky_int<T>::type>&() const; };
void f() {
A<float, float> &af = E(); A<float, int> &af2 = E();
const A<float, int> &caf2 = E();
}
template<typename T>
struct E2 {
operator T
* () const;
};
E2<int&> e2i; }
namespace crazy_declarators {
struct A {
(&operator bool())();
*operator int(); };
}
namespace smart_ptr {
class Y {
class YRef { };
Y(Y&);
public:
Y();
Y(YRef);
operator YRef(); };
struct X { explicit X(Y);
};
Y make_Y();
X f() {
X x = make_Y(); X x2(make_Y());
return X(Y());
}
}
struct Any {
Any(...);
};
struct Other {
Other(const Other &);
Other();
};
void test_any() {
Any any = Other(); }
namespace PR7055 {
struct auto_ptr {
struct auto_ptr_ref { };
auto_ptr(auto_ptr&);
auto_ptr(auto_ptr_ref);
explicit auto_ptr(int *);
operator auto_ptr_ref();
};
struct X {
X(auto_ptr);
};
X f() {
X x(auto_ptr(new int));
return X(auto_ptr(new int));
}
auto_ptr foo();
X e(foo());
struct Y {
Y(X);
};
Y f2(foo());
}
namespace PR7934 {
typedef unsigned char uint8;
struct MutablePtr {
MutablePtr() : ptr(0) {}
void *ptr;
operator void*() { return ptr; }
private:
operator uint8*() { return reinterpret_cast<uint8*>(ptr); }
operator const char*() const { return reinterpret_cast<const char*>(ptr); }
};
void fake_memcpy(const void *);
void use() {
MutablePtr ptr;
fake_memcpy(ptr);
}
}
namespace rdar8018274 {
struct X { };
struct Y {
operator const struct X *() const;
};
struct Z : Y {
operator struct X * ();
};
void test() {
Z x;
(void) (x != __null);
}
struct Base {
operator int();
};
struct Derived1 : Base { };
struct Derived2 : Base { };
struct SuperDerived : Derived1, Derived2 {
using Derived1::operator int;
};
struct UeberDerived : SuperDerived {
operator long();
};
void test2(UeberDerived ud) {
int i = ud; }
struct Base2 {
operator int();
};
struct Base3 {
operator int();
};
struct Derived23 : Base2, Base3 {
using Base2::operator int;
};
struct ExtraDerived23 : Derived23 { };
void test3(ExtraDerived23 ed) {
int i = ed;
}
}
namespace PR8065 {
template <typename T> struct Iterator;
template <typename T> struct Container;
template<>
struct Iterator<int> {
typedef Container<int> container_type;
};
template <typename T>
struct Container {
typedef typename Iterator<T>::container_type X;
operator X(void) { return X(); }
};
Container<int> test;
}
namespace PR8034 {
struct C {
operator int();
private:
template <typename T> operator T();
};
int x = C().operator int();
}
namespace PR9336 {
template<class T>
struct generic_list
{
template<class Container>
operator Container()
{
Container ar;
T* i;
ar[0]=*i;
return ar;
}
};
template<class T>
struct array
{
T& operator[](int);
const T& operator[](int)const;
};
generic_list<generic_list<int> > l;
array<array<int> > a = l;
}
namespace PR8800 {
struct A;
struct C {
operator A&();
};
void f() {
C c;
A& a1(c);
A& a2 = c;
A& a3 = static_cast<A&>(c);
A& a4 = (A&)c;
}
}
namespace PR12712 {
struct A {};
struct B {
operator A();
operator A() const;
};
struct C : B {};
A f(const C c) { return c; }
}