conversion-function.cpp revision 2def48394f6d48bde0dec2b514193c2b533265b5
1// RUN: clang -fsyntax-only -verify %s
2class X {
3public:
4  operator bool();
5  operator int() const;
6
7  bool f() {
8    return operator bool();
9  }
10
11  float g() {
12    return operator float(); // expected-error{{no conversion function to type 'float'}}
13  }
14};
15
16operator int(); // expected-error{{conversion function must be a non-static member function}}
17
18typedef int func_type(int);
19typedef int array_type[10];
20
21class Y {
22public:
23  void operator bool(int, ...) const; // expected-error{{conversion function cannot have a return type}} \
24  // expected-error{{conversion function cannot have any parameters}} \
25  // expected-error{{conversion function cannot be variadic}}
26  operator func_type(); // expected-error{{conversion function cannot convert to a function type}}
27  operator array_type(); // expected-error{{conversion function cannot convert to an array type}}
28};
29
30
31typedef int INT;
32typedef INT* INT_PTR;
33
34class Z {
35  operator int(); // expected-error{{previous declaration is here}}
36  operator int**(); // expected-error{{previous declaration is here}}
37
38  operator INT();  // expected-error{{conversion function cannot be redeclared}}
39  operator INT_PTR*(); // expected-error{{conversion function cannot be redeclared}}
40};
41
42
43class A { };
44
45class B : public A {
46public:
47  operator A&() const; // expected-warning{{conversion function converting 'class B' to its base class 'class A' will never be used}}
48  operator const void() const; // expected-warning{{conversion function converting 'class B' to 'void const' will never be used}}
49  operator const B(); // expected-warning{{conversion function converting 'class B' to itself will never be used}}
50};
51