xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/conversion-function.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -Wbind-to-temporary-copy -verify %s
2f4a2713aSLionel Sambuc class X {
3f4a2713aSLionel Sambuc public:
4f4a2713aSLionel Sambuc   operator bool();
5f4a2713aSLionel Sambuc   operator int() const;
6f4a2713aSLionel Sambuc 
f()7f4a2713aSLionel Sambuc   bool f() {
8f4a2713aSLionel Sambuc     return operator bool();
9f4a2713aSLionel Sambuc   }
10f4a2713aSLionel Sambuc 
g()11f4a2713aSLionel Sambuc   float g() {
12f4a2713aSLionel Sambuc     return operator float(); // expected-error{{use of undeclared 'operator float'}}
13f4a2713aSLionel Sambuc   }
14f4a2713aSLionel Sambuc 
15f4a2713aSLionel Sambuc   static operator short(); // expected-error{{conversion function must be a non-static member function}}
16f4a2713aSLionel Sambuc };
17f4a2713aSLionel Sambuc 
18f4a2713aSLionel Sambuc operator int(); // expected-error{{conversion function must be a non-static member function}}
19f4a2713aSLionel Sambuc 
20f4a2713aSLionel Sambuc operator int; // expected-error{{'operator int' cannot be the name of a variable or data member}}
21f4a2713aSLionel Sambuc 
22f4a2713aSLionel Sambuc typedef int func_type(int);
23f4a2713aSLionel Sambuc typedef int array_type[10];
24f4a2713aSLionel Sambuc 
25f4a2713aSLionel Sambuc class Y {
26f4a2713aSLionel Sambuc public:
27f4a2713aSLionel Sambuc   void operator bool(int, ...) const; // expected-error{{conversion function cannot have a return type}} \
28f4a2713aSLionel Sambuc   // expected-error{{conversion function cannot have any parameters}}
29f4a2713aSLionel Sambuc 
30*0a6a1f1dSLionel Sambuc   operator bool(int a = 4, int b = 6) const; // expected-error{{conversion function cannot have any parameters}}
31*0a6a1f1dSLionel Sambuc 
32*0a6a1f1dSLionel Sambuc 
33f4a2713aSLionel Sambuc   operator float(...) const;  // expected-error{{conversion function cannot be variadic}}
34f4a2713aSLionel Sambuc 
35f4a2713aSLionel Sambuc 
36f4a2713aSLionel Sambuc   operator func_type(); // expected-error{{conversion function cannot convert to a function type}}
37f4a2713aSLionel Sambuc   operator array_type(); // expected-error{{conversion function cannot convert to an array type}}
38f4a2713aSLionel Sambuc };
39f4a2713aSLionel Sambuc 
40f4a2713aSLionel Sambuc 
41f4a2713aSLionel Sambuc typedef int INT;
42f4a2713aSLionel Sambuc typedef INT* INT_PTR;
43f4a2713aSLionel Sambuc 
44f4a2713aSLionel Sambuc class Z {
45f4a2713aSLionel Sambuc   operator int(); // expected-note {{previous declaration is here}}
46f4a2713aSLionel Sambuc   operator int**(); // expected-note {{previous declaration is here}}
47f4a2713aSLionel Sambuc 
48f4a2713aSLionel Sambuc   operator INT();  // expected-error{{conversion function cannot be redeclared}}
49f4a2713aSLionel Sambuc   operator INT_PTR*(); // expected-error{{conversion function cannot be redeclared}}
50f4a2713aSLionel Sambuc };
51f4a2713aSLionel Sambuc 
52f4a2713aSLionel Sambuc 
53f4a2713aSLionel Sambuc class A { };
54f4a2713aSLionel Sambuc 
55f4a2713aSLionel Sambuc class B : public A {
56f4a2713aSLionel Sambuc public:
57f4a2713aSLionel Sambuc   operator A&() const; // expected-warning{{conversion function converting 'B' to its base class 'A' will never be used}}
58f4a2713aSLionel Sambuc   operator const void() const; // expected-warning{{conversion function converting 'B' to 'const void' will never be used}}
59f4a2713aSLionel Sambuc   operator const B(); // expected-warning{{conversion function converting 'B' to itself will never be used}}
60f4a2713aSLionel Sambuc };
61f4a2713aSLionel Sambuc 
62f4a2713aSLionel Sambuc // This used to crash Clang.
63f4a2713aSLionel Sambuc struct Flip;
64f4a2713aSLionel Sambuc struct Flop {
65f4a2713aSLionel Sambuc   Flop();
66f4a2713aSLionel Sambuc   Flop(const Flip&); // expected-note{{candidate constructor}}
67f4a2713aSLionel Sambuc };
68f4a2713aSLionel Sambuc struct Flip {
69f4a2713aSLionel Sambuc   operator Flop() const; // expected-note{{candidate function}}
70f4a2713aSLionel Sambuc };
71f4a2713aSLionel Sambuc Flop flop = Flip(); // expected-error {{conversion from 'Flip' to 'Flop' is ambiguous}}
72f4a2713aSLionel Sambuc 
73f4a2713aSLionel Sambuc // This tests that we don't add the second conversion declaration to the list of user conversions
74f4a2713aSLionel Sambuc struct C {
75f4a2713aSLionel Sambuc   operator const char *() const;
76f4a2713aSLionel Sambuc };
77f4a2713aSLionel Sambuc 
operator const char*() const78f4a2713aSLionel Sambuc C::operator const char*() const { return 0; }
79f4a2713aSLionel Sambuc 
f(const C & c)80f4a2713aSLionel Sambuc void f(const C& c) {
81f4a2713aSLionel Sambuc   const char* v = c;
82f4a2713aSLionel Sambuc }
83f4a2713aSLionel Sambuc 
84f4a2713aSLionel Sambuc // Test. Conversion in base class is visible in derived class.
85f4a2713aSLionel Sambuc class XB {
86f4a2713aSLionel Sambuc public:
87f4a2713aSLionel Sambuc   operator int(); // expected-note {{candidate function}}
88f4a2713aSLionel Sambuc };
89f4a2713aSLionel Sambuc 
90f4a2713aSLionel Sambuc class Yb : public XB {
91f4a2713aSLionel Sambuc public:
92f4a2713aSLionel Sambuc   operator char(); // expected-note {{candidate function}}
93f4a2713aSLionel Sambuc };
94f4a2713aSLionel Sambuc 
f(Yb & a)95f4a2713aSLionel Sambuc void f(Yb& a) {
96f4a2713aSLionel Sambuc   if (a) { } // expected-error {{conversion from 'Yb' to 'bool' is ambiguous}}
97f4a2713aSLionel Sambuc   int i = a; // OK. calls XB::operator int();
98f4a2713aSLionel Sambuc   char ch = a;  // OK. calls Yb::operator char();
99f4a2713aSLionel Sambuc }
100f4a2713aSLionel Sambuc 
101f4a2713aSLionel Sambuc // Test conversion + copy construction.
102f4a2713aSLionel Sambuc class AutoPtrRef { };
103f4a2713aSLionel Sambuc 
104f4a2713aSLionel Sambuc class AutoPtr {
105f4a2713aSLionel Sambuc   AutoPtr(AutoPtr &); // expected-note{{declared private here}}
106f4a2713aSLionel Sambuc 
107f4a2713aSLionel Sambuc public:
108f4a2713aSLionel Sambuc   AutoPtr();
109f4a2713aSLionel Sambuc   AutoPtr(AutoPtrRef);
110f4a2713aSLionel Sambuc 
111f4a2713aSLionel Sambuc   operator AutoPtrRef();
112f4a2713aSLionel Sambuc };
113f4a2713aSLionel Sambuc 
114f4a2713aSLionel Sambuc AutoPtr make_auto_ptr();
115f4a2713aSLionel Sambuc 
test_auto_ptr(bool Cond)116f4a2713aSLionel Sambuc AutoPtr test_auto_ptr(bool Cond) {
117f4a2713aSLionel Sambuc   AutoPtr p1( make_auto_ptr() );
118f4a2713aSLionel Sambuc 
119f4a2713aSLionel Sambuc   AutoPtr p;
120f4a2713aSLionel Sambuc   if (Cond)
121f4a2713aSLionel Sambuc     return p; // expected-error{{calling a private constructor}}
122f4a2713aSLionel Sambuc 
123f4a2713aSLionel Sambuc   return AutoPtr();
124f4a2713aSLionel Sambuc }
125f4a2713aSLionel Sambuc 
126f4a2713aSLionel Sambuc struct A1 {
127f4a2713aSLionel Sambuc   A1(const char *);
128f4a2713aSLionel Sambuc   ~A1();
129f4a2713aSLionel Sambuc 
130f4a2713aSLionel Sambuc private:
131f4a2713aSLionel Sambuc   A1(const A1&); // expected-note 2 {{declared private here}}
132f4a2713aSLionel Sambuc };
133f4a2713aSLionel Sambuc 
f()134f4a2713aSLionel Sambuc A1 f() {
135f4a2713aSLionel Sambuc   // FIXME: redundant diagnostics!
136f4a2713aSLionel Sambuc   return "Hello"; // expected-error {{calling a private constructor}} expected-warning {{an accessible copy constructor}}
137f4a2713aSLionel Sambuc }
138f4a2713aSLionel Sambuc 
139f4a2713aSLionel Sambuc namespace source_locations {
140f4a2713aSLionel Sambuc   template<typename T>
141f4a2713aSLionel Sambuc   struct sneaky_int {
142f4a2713aSLionel Sambuc     typedef int type;
143f4a2713aSLionel Sambuc   };
144f4a2713aSLionel Sambuc 
145f4a2713aSLionel Sambuc   template<typename T, typename U>
146f4a2713aSLionel Sambuc   struct A { };
147f4a2713aSLionel Sambuc 
148f4a2713aSLionel Sambuc   template<typename T>
149f4a2713aSLionel Sambuc   struct A<T, T> : A<T, int> { };
150f4a2713aSLionel Sambuc 
151f4a2713aSLionel Sambuc   struct E {
152f4a2713aSLionel Sambuc     template<typename T>
153f4a2713aSLionel Sambuc     operator A<T, typename sneaky_int<T>::type>&() const; // expected-note{{candidate function}}
154f4a2713aSLionel Sambuc   };
155f4a2713aSLionel Sambuc 
f()156f4a2713aSLionel Sambuc   void f() {
157f4a2713aSLionel Sambuc     A<float, float> &af = E(); // expected-error{{no viable conversion}}
158f4a2713aSLionel Sambuc     A<float, int> &af2 = E();
159f4a2713aSLionel Sambuc     const A<float, int> &caf2 = E();
160f4a2713aSLionel Sambuc   }
161f4a2713aSLionel Sambuc 
162f4a2713aSLionel Sambuc   // Check
163f4a2713aSLionel Sambuc   template<typename T>
164f4a2713aSLionel Sambuc   struct E2 {
165f4a2713aSLionel Sambuc     operator T
166f4a2713aSLionel Sambuc     * // expected-error{{pointer to a reference}}
167f4a2713aSLionel Sambuc     () const;
168f4a2713aSLionel Sambuc   };
169f4a2713aSLionel Sambuc 
170f4a2713aSLionel Sambuc   E2<int&> e2i; // expected-note{{in instantiation}}
171f4a2713aSLionel Sambuc }
172f4a2713aSLionel Sambuc 
173f4a2713aSLionel Sambuc namespace crazy_declarators {
174f4a2713aSLionel Sambuc   struct A {
175*0a6a1f1dSLionel Sambuc     (&operator bool())(); // expected-error {{use a typedef to declare a conversion to 'bool (&)()'}}
176*0a6a1f1dSLionel Sambuc     *operator int();  // expected-error {{put the complete type after 'operator'}}
177*0a6a1f1dSLionel Sambuc     // No suggestion of using a typedef here; that's not possible.
178*0a6a1f1dSLionel Sambuc     template<typename T> (&operator T())(); // expected-error-re {{cannot specify any part of a return type in the declaration of a conversion function{{$}}}}
179f4a2713aSLionel Sambuc   };
180f4a2713aSLionel Sambuc }
181f4a2713aSLionel Sambuc 
182f4a2713aSLionel Sambuc namespace smart_ptr {
183f4a2713aSLionel Sambuc   class Y {
184f4a2713aSLionel Sambuc     class YRef { };
185f4a2713aSLionel Sambuc 
186f4a2713aSLionel Sambuc     Y(Y&);
187f4a2713aSLionel Sambuc 
188f4a2713aSLionel Sambuc   public:
189f4a2713aSLionel Sambuc     Y();
190f4a2713aSLionel Sambuc     Y(YRef);
191f4a2713aSLionel Sambuc 
192f4a2713aSLionel Sambuc     operator YRef(); // expected-note{{candidate function}}
193f4a2713aSLionel Sambuc   };
194f4a2713aSLionel Sambuc 
195f4a2713aSLionel Sambuc   struct X { // expected-note{{candidate constructor (the implicit copy constructor) not}}
196f4a2713aSLionel Sambuc     explicit X(Y);
197f4a2713aSLionel Sambuc   };
198f4a2713aSLionel Sambuc 
199f4a2713aSLionel Sambuc   Y make_Y();
200f4a2713aSLionel Sambuc 
f()201f4a2713aSLionel Sambuc   X f() {
202f4a2713aSLionel Sambuc     X x = make_Y(); // expected-error{{no viable conversion from 'smart_ptr::Y' to 'smart_ptr::X'}}
203f4a2713aSLionel Sambuc     X x2(make_Y());
204f4a2713aSLionel Sambuc     return X(Y());
205f4a2713aSLionel Sambuc   }
206f4a2713aSLionel Sambuc }
207f4a2713aSLionel Sambuc 
208f4a2713aSLionel Sambuc struct Any {
209f4a2713aSLionel Sambuc   Any(...);
210f4a2713aSLionel Sambuc };
211f4a2713aSLionel Sambuc 
212f4a2713aSLionel Sambuc struct Other {
213f4a2713aSLionel Sambuc   Other(const Other &);
214f4a2713aSLionel Sambuc   Other();
215f4a2713aSLionel Sambuc };
216f4a2713aSLionel Sambuc 
test_any()217f4a2713aSLionel Sambuc void test_any() {
218f4a2713aSLionel Sambuc   Any any = Other(); // expected-error{{cannot pass object of non-POD type 'Other' through variadic constructor; call will abort at runtime}}
219f4a2713aSLionel Sambuc }
220f4a2713aSLionel Sambuc 
221f4a2713aSLionel Sambuc namespace PR7055 {
222f4a2713aSLionel Sambuc   // Make sure that we don't allow too many conversions in an
223f4a2713aSLionel Sambuc   // auto_ptr-like template. In particular, we can't create multiple
224f4a2713aSLionel Sambuc   // temporary objects when binding to a reference.
225f4a2713aSLionel Sambuc   struct auto_ptr {
226f4a2713aSLionel Sambuc     struct auto_ptr_ref { };
227f4a2713aSLionel Sambuc 
228f4a2713aSLionel Sambuc     auto_ptr(auto_ptr&);
229f4a2713aSLionel Sambuc     auto_ptr(auto_ptr_ref);
230f4a2713aSLionel Sambuc     explicit auto_ptr(int *);
231f4a2713aSLionel Sambuc 
232f4a2713aSLionel Sambuc     operator auto_ptr_ref();
233f4a2713aSLionel Sambuc   };
234f4a2713aSLionel Sambuc 
235f4a2713aSLionel Sambuc   struct X {
236f4a2713aSLionel Sambuc     X(auto_ptr);
237f4a2713aSLionel Sambuc   };
238f4a2713aSLionel Sambuc 
f()239f4a2713aSLionel Sambuc   X f() {
240f4a2713aSLionel Sambuc     X x(auto_ptr(new int));
241f4a2713aSLionel Sambuc     return X(auto_ptr(new int));
242f4a2713aSLionel Sambuc   }
243f4a2713aSLionel Sambuc 
244f4a2713aSLionel Sambuc   auto_ptr foo();
245f4a2713aSLionel Sambuc 
246f4a2713aSLionel Sambuc   X e(foo());
247f4a2713aSLionel Sambuc 
248f4a2713aSLionel Sambuc   struct Y {
249f4a2713aSLionel Sambuc     Y(X);
250f4a2713aSLionel Sambuc   };
251f4a2713aSLionel Sambuc 
252f4a2713aSLionel Sambuc   Y f2(foo());
253f4a2713aSLionel Sambuc }
254f4a2713aSLionel Sambuc 
255f4a2713aSLionel Sambuc namespace PR7934 {
256f4a2713aSLionel Sambuc   typedef unsigned char uint8;
257f4a2713aSLionel Sambuc 
258f4a2713aSLionel Sambuc   struct MutablePtr {
MutablePtrPR7934::MutablePtr259f4a2713aSLionel Sambuc     MutablePtr() : ptr(0) {}
260f4a2713aSLionel Sambuc     void *ptr;
261f4a2713aSLionel Sambuc 
operator void*PR7934::MutablePtr262f4a2713aSLionel Sambuc     operator void*() { return ptr; }
263f4a2713aSLionel Sambuc 
264f4a2713aSLionel Sambuc   private:
operator uint8*PR7934::MutablePtr265f4a2713aSLionel Sambuc     operator uint8*() { return reinterpret_cast<uint8*>(ptr); }
operator const char*PR7934::MutablePtr266f4a2713aSLionel Sambuc     operator const char*() const { return reinterpret_cast<const char*>(ptr); }
267f4a2713aSLionel Sambuc   };
268f4a2713aSLionel Sambuc 
269f4a2713aSLionel Sambuc   void fake_memcpy(const void *);
270f4a2713aSLionel Sambuc 
use()271f4a2713aSLionel Sambuc   void use() {
272f4a2713aSLionel Sambuc     MutablePtr ptr;
273f4a2713aSLionel Sambuc     fake_memcpy(ptr);
274f4a2713aSLionel Sambuc   }
275f4a2713aSLionel Sambuc }
276f4a2713aSLionel Sambuc 
277f4a2713aSLionel Sambuc namespace rdar8018274 {
278f4a2713aSLionel Sambuc   struct X { };
279f4a2713aSLionel Sambuc   struct Y {
280f4a2713aSLionel Sambuc     operator const struct X *() const;
281f4a2713aSLionel Sambuc   };
282f4a2713aSLionel Sambuc 
283f4a2713aSLionel Sambuc   struct Z : Y {
284f4a2713aSLionel Sambuc     operator struct X * ();
285f4a2713aSLionel Sambuc   };
286f4a2713aSLionel Sambuc 
test()287f4a2713aSLionel Sambuc   void test() {
288f4a2713aSLionel Sambuc     Z x;
289f4a2713aSLionel Sambuc     (void) (x != __null);
290f4a2713aSLionel Sambuc   }
291f4a2713aSLionel Sambuc 
292f4a2713aSLionel Sambuc 
293f4a2713aSLionel Sambuc   struct Base {
294f4a2713aSLionel Sambuc     operator int();
295f4a2713aSLionel Sambuc   };
296f4a2713aSLionel Sambuc 
297f4a2713aSLionel Sambuc   struct Derived1 : Base { };
298f4a2713aSLionel Sambuc 
299f4a2713aSLionel Sambuc   struct Derived2 : Base { };
300f4a2713aSLionel Sambuc 
301f4a2713aSLionel Sambuc   struct SuperDerived : Derived1, Derived2 {
302f4a2713aSLionel Sambuc     using Derived1::operator int;
303f4a2713aSLionel Sambuc   };
304f4a2713aSLionel Sambuc 
305f4a2713aSLionel Sambuc   struct UeberDerived : SuperDerived {
306f4a2713aSLionel Sambuc     operator long();
307f4a2713aSLionel Sambuc   };
308f4a2713aSLionel Sambuc 
test2(UeberDerived ud)309f4a2713aSLionel Sambuc   void test2(UeberDerived ud) {
310f4a2713aSLionel Sambuc     int i = ud; // expected-error{{ambiguous conversion from derived class 'rdar8018274::SuperDerived' to base class 'rdar8018274::Base'}}
311f4a2713aSLionel Sambuc   }
312f4a2713aSLionel Sambuc 
313f4a2713aSLionel Sambuc   struct Base2 {
314f4a2713aSLionel Sambuc     operator int();
315f4a2713aSLionel Sambuc   };
316f4a2713aSLionel Sambuc 
317f4a2713aSLionel Sambuc   struct Base3 {
318f4a2713aSLionel Sambuc     operator int();
319f4a2713aSLionel Sambuc   };
320f4a2713aSLionel Sambuc 
321f4a2713aSLionel Sambuc   struct Derived23 : Base2, Base3 {
322f4a2713aSLionel Sambuc     using Base2::operator int;
323f4a2713aSLionel Sambuc   };
324f4a2713aSLionel Sambuc 
325f4a2713aSLionel Sambuc   struct ExtraDerived23 : Derived23 { };
326f4a2713aSLionel Sambuc 
test3(ExtraDerived23 ed)327f4a2713aSLionel Sambuc   void test3(ExtraDerived23 ed) {
328f4a2713aSLionel Sambuc     int i = ed;
329f4a2713aSLionel Sambuc   }
330f4a2713aSLionel Sambuc }
331f4a2713aSLionel Sambuc 
332f4a2713aSLionel Sambuc namespace PR8065 {
333f4a2713aSLionel Sambuc   template <typename T> struct Iterator;
334f4a2713aSLionel Sambuc   template <typename T> struct Container;
335f4a2713aSLionel Sambuc 
336f4a2713aSLionel Sambuc   template<>
337f4a2713aSLionel Sambuc   struct Iterator<int> {
338f4a2713aSLionel Sambuc     typedef Container<int> container_type;
339f4a2713aSLionel Sambuc   };
340f4a2713aSLionel Sambuc 
341f4a2713aSLionel Sambuc   template <typename T>
342f4a2713aSLionel Sambuc   struct Container {
343f4a2713aSLionel Sambuc     typedef typename Iterator<T>::container_type X;
operator XPR8065::Container344f4a2713aSLionel Sambuc     operator X(void) { return X(); }
345f4a2713aSLionel Sambuc   };
346f4a2713aSLionel Sambuc 
347f4a2713aSLionel Sambuc   Container<int> test;
348f4a2713aSLionel Sambuc }
349f4a2713aSLionel Sambuc 
350f4a2713aSLionel Sambuc namespace PR8034 {
351f4a2713aSLionel Sambuc   struct C {
352f4a2713aSLionel Sambuc     operator int();
353f4a2713aSLionel Sambuc 
354f4a2713aSLionel Sambuc   private:
355f4a2713aSLionel Sambuc     template <typename T> operator T();
356f4a2713aSLionel Sambuc   };
357f4a2713aSLionel Sambuc   int x = C().operator int();
358f4a2713aSLionel Sambuc }
359f4a2713aSLionel Sambuc 
360f4a2713aSLionel Sambuc namespace PR9336 {
361f4a2713aSLionel Sambuc   template<class T>
362f4a2713aSLionel Sambuc   struct generic_list
363f4a2713aSLionel Sambuc   {
364f4a2713aSLionel Sambuc     template<class Container>
operator ContainerPR9336::generic_list365f4a2713aSLionel Sambuc     operator Container()
366f4a2713aSLionel Sambuc     {
367f4a2713aSLionel Sambuc       Container ar;
368f4a2713aSLionel Sambuc       T* i;
369f4a2713aSLionel Sambuc       ar[0]=*i;
370f4a2713aSLionel Sambuc       return ar;
371f4a2713aSLionel Sambuc     }
372f4a2713aSLionel Sambuc   };
373f4a2713aSLionel Sambuc 
374f4a2713aSLionel Sambuc   template<class T>
375f4a2713aSLionel Sambuc   struct array
376f4a2713aSLionel Sambuc   {
377f4a2713aSLionel Sambuc     T& operator[](int);
378f4a2713aSLionel Sambuc     const T& operator[](int)const;
379f4a2713aSLionel Sambuc   };
380f4a2713aSLionel Sambuc 
381f4a2713aSLionel Sambuc   generic_list<generic_list<int> > l;
382f4a2713aSLionel Sambuc   array<array<int> > a = l;
383f4a2713aSLionel Sambuc }
384f4a2713aSLionel Sambuc 
385f4a2713aSLionel Sambuc namespace PR8800 {
386f4a2713aSLionel Sambuc   struct A;
387f4a2713aSLionel Sambuc   struct C {
388f4a2713aSLionel Sambuc     operator A&();
389f4a2713aSLionel Sambuc   };
f()390f4a2713aSLionel Sambuc   void f() {
391f4a2713aSLionel Sambuc     C c;
392f4a2713aSLionel Sambuc     A& a1(c);
393f4a2713aSLionel Sambuc     A& a2 = c;
394f4a2713aSLionel Sambuc     A& a3 = static_cast<A&>(c);
395f4a2713aSLionel Sambuc     A& a4 = (A&)c;
396f4a2713aSLionel Sambuc   }
397f4a2713aSLionel Sambuc }
398f4a2713aSLionel Sambuc 
399f4a2713aSLionel Sambuc namespace PR12712 {
400f4a2713aSLionel Sambuc   struct A {};
401f4a2713aSLionel Sambuc   struct B {
402f4a2713aSLionel Sambuc     operator A();
403f4a2713aSLionel Sambuc     operator A() const;
404f4a2713aSLionel Sambuc   };
405f4a2713aSLionel Sambuc   struct C : B {};
406f4a2713aSLionel Sambuc 
f(const C c)407f4a2713aSLionel Sambuc   A f(const C c) { return c; }
408f4a2713aSLionel Sambuc }
409*0a6a1f1dSLionel Sambuc 
410*0a6a1f1dSLionel Sambuc namespace PR18234 {
411*0a6a1f1dSLionel Sambuc   struct A {
412*0a6a1f1dSLionel Sambuc     operator enum E { e } (); // expected-error {{'PR18234::A::E' cannot be defined in a type specifier}}
413*0a6a1f1dSLionel Sambuc     operator struct S { int n; } (); // expected-error {{'PR18234::A::S' cannot be defined in a type specifier}}
414*0a6a1f1dSLionel Sambuc   } a;
415*0a6a1f1dSLionel Sambuc   A::S s = a;
416*0a6a1f1dSLionel Sambuc   A::E e = a; // expected-note {{here}}
417*0a6a1f1dSLionel Sambuc   bool k1 = e == A::e; // expected-error {{no member named 'e'}}
418*0a6a1f1dSLionel Sambuc   bool k2 = e.n == 0;
419*0a6a1f1dSLionel Sambuc }
420