1 // RUN: %clang_cc1 -fsyntax-only -verify %s
8 return operator bool();
12 return operator float(); // expected-error{{use of undeclared 'operator float'}}
16 operator int(); // expected-error{{conversion function must be a non-static member function}}
18 operator int; // expected-error{{'operator int' cannot be the name of a variable or data member}}
20 typedef int func_type(int);
21 typedef int array_type[10];
25 void operator bool(int, ...) const; // expected-error{{conversion function cannot have a return type}} \
26 // expected-error{{conversion function cannot have any parameters}}
28 operator float(...) const; // expected-error{{conversion function cannot be variadic}}
31 operator func_type(); // expected-error{{conversion function cannot convert to a function type}}
32 operator array_type(); // expected-error{{conversion function cannot convert to an array type}}
40 operator int(); // expected-note {{previous declaration is here}}
41 operator int**(); // expected-note {{previous declaration is here}}
43 operator INT(); // expected-error{{conversion function cannot be redeclared}}
44 operator INT_PTR*(); // expected-error{{conversion function cannot be redeclared}}
52 operator A&() const; // expected-warning{{conversion function converting 'B' to its base class 'A' will never be used}}
53 operator const void() const; // expected-warning{{conversion function converting 'B' to 'const void' will never be used}}
54 operator const B(); // expected-warning{{conversion function converting 'B' to itself will never be used}}
57 // This used to crash Clang.
61 Flop(const Flip&); // expected-note{{candidate constructor}}
64 operator Flop() const; // expected-note{{candidate function}}
66 Flop flop = Flip(); // expected-error {{conversion from 'Flip' to 'Flop' is ambiguous}}
68 // This tests that we don't add the second conversion declaration to the list of user conversions
70 operator const char *() const;
73 C::operator const char*() const { return 0; }
79 // Test. Conversion in base class is visible in derived class.
82 operator int(); // expected-note {{candidate function}}
85 class Yb : public XB {
87 operator char(); // expected-note {{candidate function}}
91 if (a) { } // expected-error {{conversion from 'Yb' to 'bool' is ambiguous}}
92 int i = a; // OK. calls XB::operator int();
93 char ch = a; // OK. calls Yb::operator char();
96 // Test conversion + copy construction.
100 AutoPtr(AutoPtr &); // expected-note{{declared private here}}
106 operator AutoPtrRef();
109 AutoPtr make_auto_ptr();
111 AutoPtr test_auto_ptr(bool Cond) {
112 AutoPtr p1( make_auto_ptr() );
116 return p; // expected-error{{calling a private constructor}}
126 A1(const A1&); // expected-note 2 {{declared private here}}
130 // FIXME: redundant diagnostics!
131 return "Hello"; // expected-error {{calling a private constructor}} expected-warning {{an accessible copy constructor}}
134 namespace source_locations {
140 template<typename T, typename U>
144 struct A<T, T> : A<T, int> { };
148 operator A<T, typename sneaky_int<T>::type>&() const; // expected-note{{candidate function}}
152 A<float, float> &af = E(); // expected-error{{no viable conversion}}
153 A<float, int> &af2 = E();
154 const A<float, int> &caf2 = E();
161 * // expected-error{{pointer to a reference}}
165 E2<int&> e2i; // expected-note{{in instantiation}}
168 namespace crazy_declarators {
170 (&operator bool())(); // expected-error {{must use a typedef to declare a conversion to 'bool (&)()'}}
172 // FIXME: This diagnostic is misleading (the correct spelling
173 // would be 'operator int*'), but it's a corner case of a
174 // rarely-used syntax extension.
175 *operator int(); // expected-error {{must use a typedef to declare a conversion to 'int *'}}
179 namespace smart_ptr {
189 operator YRef(); // expected-note{{candidate function}}
192 struct X { // expected-note{{candidate constructor (the implicit copy constructor) not}}
199 X x = make_Y(); // expected-error{{no viable conversion from 'smart_ptr::Y' to 'smart_ptr::X'}}
210 Other(const Other &);
215 Any any = Other(); // expected-error{{cannot pass object of non-POD type 'Other' through variadic constructor; call will abort at runtime}}
219 // Make sure that we don't allow too many conversions in an
220 // auto_ptr-like template. In particular, we can't create multiple
221 // temporary objects when binding to a reference.
223 struct auto_ptr_ref { };
226 auto_ptr(auto_ptr_ref);
227 explicit auto_ptr(int *);
229 operator auto_ptr_ref();
237 X x(auto_ptr(new int));
238 return X(auto_ptr(new int));
253 typedef unsigned char uint8;
256 MutablePtr() : ptr(0) {}
259 operator void*() { return ptr; }
262 operator uint8*() { return reinterpret_cast<uint8*>(ptr); }
263 operator const char*() const { return reinterpret_cast<const char*>(ptr); }
266 void fake_memcpy(const void *);
274 namespace rdar8018274 {
277 operator const struct X *() const;
281 operator struct X * ();
286 (void) (x != __null);
294 struct Derived1 : Base { };
296 struct Derived2 : Base { };
298 struct SuperDerived : Derived1, Derived2 {
299 using Derived1::operator int;
302 struct UeberDerived : SuperDerived {
306 void test2(UeberDerived ud) {
307 int i = ud; // expected-error{{ambiguous conversion from derived class 'rdar8018274::SuperDerived' to base class 'rdar8018274::Base'}}
318 struct Derived23 : Base2, Base3 {
319 using Base2::operator int;
322 struct ExtraDerived23 : Derived23 { };
324 void test3(ExtraDerived23 ed) {
330 template <typename T> struct Iterator;
331 template <typename T> struct Container;
334 struct Iterator<int> {
335 typedef Container<int> container_type;
338 template <typename T>
340 typedef typename Iterator<T>::container_type X;
341 operator X(void) { return X(); }
352 template <typename T> operator T();
354 int x = C().operator int();
361 template<class Container>
375 const T& operator[](int)const;
378 generic_list<generic_list<int> > l;
379 array<array<int> > a = l;
391 A& a3 = static_cast<A&>(c);