1 // RUN: %clang_cc1 -fsyntax-only -verify %s
8 return operator bool();
12 return operator float(); // expected-error{{use of undeclared 'operator float'}}
15 static operator short(); // expected-error{{conversion function must be a non-static member function}}
18 operator int(); // expected-error{{conversion function must be a non-static member function}}
20 operator int; // expected-error{{'operator int' cannot be the name of a variable or data member}}
22 typedef int func_type(int);
23 typedef int array_type[10];
27 void operator bool(int, ...) const; // expected-error{{conversion function cannot have a return type}} \
28 // expected-error{{conversion function cannot have any parameters}}
30 operator float(...) const; // expected-error{{conversion function cannot be variadic}}
33 operator func_type(); // expected-error{{conversion function cannot convert to a function type}}
34 operator array_type(); // expected-error{{conversion function cannot convert to an array type}}
42 operator int(); // expected-note {{previous declaration is here}}
43 operator int**(); // expected-note {{previous declaration is here}}
45 operator INT(); // expected-error{{conversion function cannot be redeclared}}
46 operator INT_PTR*(); // expected-error{{conversion function cannot be redeclared}}
54 operator A&() const; // expected-warning{{conversion function converting 'B' to its base class 'A' will never be used}}
55 operator const void() const; // expected-warning{{conversion function converting 'B' to 'const void' will never be used}}
56 operator const B(); // expected-warning{{conversion function converting 'B' to itself will never be used}}
59 // This used to crash Clang.
63 Flop(const Flip&); // expected-note{{candidate constructor}}
66 operator Flop() const; // expected-note{{candidate function}}
68 Flop flop = Flip(); // expected-error {{conversion from 'Flip' to 'Flop' is ambiguous}}
70 // This tests that we don't add the second conversion declaration to the list of user conversions
72 operator const char *() const;
75 C::operator const char*() const { return 0; }
81 // Test. Conversion in base class is visible in derived class.
84 operator int(); // expected-note {{candidate function}}
87 class Yb : public XB {
89 operator char(); // expected-note {{candidate function}}
93 if (a) { } // expected-error {{conversion from 'Yb' to 'bool' is ambiguous}}
94 int i = a; // OK. calls XB::operator int();
95 char ch = a; // OK. calls Yb::operator char();
98 // Test conversion + copy construction.
102 AutoPtr(AutoPtr &); // expected-note{{declared private here}}
108 operator AutoPtrRef();
111 AutoPtr make_auto_ptr();
113 AutoPtr test_auto_ptr(bool Cond) {
114 AutoPtr p1( make_auto_ptr() );
118 return p; // expected-error{{calling a private constructor}}
128 A1(const A1&); // expected-note 2 {{declared private here}}
132 // FIXME: redundant diagnostics!
133 return "Hello"; // expected-error {{calling a private constructor}} expected-warning {{an accessible copy constructor}}
136 namespace source_locations {
142 template<typename T, typename U>
146 struct A<T, T> : A<T, int> { };
150 operator A<T, typename sneaky_int<T>::type>&() const; // expected-note{{candidate function}}
154 A<float, float> &af = E(); // expected-error{{no viable conversion}}
155 A<float, int> &af2 = E();
156 const A<float, int> &caf2 = E();
163 * // expected-error{{pointer to a reference}}
167 E2<int&> e2i; // expected-note{{in instantiation}}
170 namespace crazy_declarators {
172 (&operator bool())(); // expected-error {{must use a typedef to declare a conversion to 'bool (&)()'}}
174 // FIXME: This diagnostic is misleading (the correct spelling
175 // would be 'operator int*'), but it's a corner case of a
176 // rarely-used syntax extension.
177 *operator int(); // expected-error {{must use a typedef to declare a conversion to 'int *'}}
181 namespace smart_ptr {
191 operator YRef(); // expected-note{{candidate function}}
194 struct X { // expected-note{{candidate constructor (the implicit copy constructor) not}}
201 X x = make_Y(); // expected-error{{no viable conversion from 'smart_ptr::Y' to 'smart_ptr::X'}}
212 Other(const Other &);
217 Any any = Other(); // expected-error{{cannot pass object of non-POD type 'Other' through variadic constructor; call will abort at runtime}}
221 // Make sure that we don't allow too many conversions in an
222 // auto_ptr-like template. In particular, we can't create multiple
223 // temporary objects when binding to a reference.
225 struct auto_ptr_ref { };
228 auto_ptr(auto_ptr_ref);
229 explicit auto_ptr(int *);
231 operator auto_ptr_ref();
239 X x(auto_ptr(new int));
240 return X(auto_ptr(new int));
255 typedef unsigned char uint8;
258 MutablePtr() : ptr(0) {}
261 operator void*() { return ptr; }
264 operator uint8*() { return reinterpret_cast<uint8*>(ptr); }
265 operator const char*() const { return reinterpret_cast<const char*>(ptr); }
268 void fake_memcpy(const void *);
276 namespace rdar8018274 {
279 operator const struct X *() const;
283 operator struct X * ();
288 (void) (x != __null);
296 struct Derived1 : Base { };
298 struct Derived2 : Base { };
300 struct SuperDerived : Derived1, Derived2 {
301 using Derived1::operator int;
304 struct UeberDerived : SuperDerived {
308 void test2(UeberDerived ud) {
309 int i = ud; // expected-error{{ambiguous conversion from derived class 'rdar8018274::SuperDerived' to base class 'rdar8018274::Base'}}
320 struct Derived23 : Base2, Base3 {
321 using Base2::operator int;
324 struct ExtraDerived23 : Derived23 { };
326 void test3(ExtraDerived23 ed) {
332 template <typename T> struct Iterator;
333 template <typename T> struct Container;
336 struct Iterator<int> {
337 typedef Container<int> container_type;
340 template <typename T>
342 typedef typename Iterator<T>::container_type X;
343 operator X(void) { return X(); }
354 template <typename T> operator T();
356 int x = C().operator int();
363 template<class Container>
377 const T& operator[](int)const;
380 generic_list<generic_list<int> > l;
381 array<array<int> > a = l;
393 A& a3 = static_cast<A&>(c);
406 A f(const C c) { return c; }