xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/conditional-expr.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 -Wsign-conversion %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc // C++ rules for ?: are a lot stricter than C rules, and have to take into
4f4a2713aSLionel Sambuc // account more conversion options.
5f4a2713aSLionel Sambuc // This test runs in C++11 mode for the contextual conversion of the condition.
6f4a2713aSLionel Sambuc 
7f4a2713aSLionel Sambuc struct ToBool { explicit operator bool(); };
8f4a2713aSLionel Sambuc 
9f4a2713aSLionel Sambuc struct B;
10f4a2713aSLionel Sambuc struct A {
11f4a2713aSLionel Sambuc   A();
12f4a2713aSLionel Sambuc   A(const B&); // expected-note 2 {{candidate constructor}}
13f4a2713aSLionel Sambuc };
14f4a2713aSLionel Sambuc struct B { operator A() const; }; // expected-note 2 {{candidate function}}
15f4a2713aSLionel Sambuc struct I { operator int(); };
16f4a2713aSLionel Sambuc struct J { operator I(); };
17f4a2713aSLionel Sambuc struct K { operator double(); };
18f4a2713aSLionel Sambuc typedef void (*vfn)();
19f4a2713aSLionel Sambuc struct F { operator vfn(); };
20f4a2713aSLionel Sambuc struct G { operator vfn(); };
21f4a2713aSLionel Sambuc 
22f4a2713aSLionel Sambuc struct Base {
23f4a2713aSLionel Sambuc   int trick();
24f4a2713aSLionel Sambuc   A trick() const;
25f4a2713aSLionel Sambuc   void fn1();
26f4a2713aSLionel Sambuc };
27f4a2713aSLionel Sambuc struct Derived : Base {
28f4a2713aSLionel Sambuc   void fn2();
29f4a2713aSLionel Sambuc };
30f4a2713aSLionel Sambuc struct Convertible { operator Base&(); };
31f4a2713aSLionel Sambuc struct Priv : private Base {}; // expected-note 4 {{declared private here}}
32f4a2713aSLionel Sambuc struct Mid : Base {};
33f4a2713aSLionel Sambuc struct Fin : Mid, Derived {};
34f4a2713aSLionel Sambuc typedef void (Derived::*DFnPtr)();
35f4a2713aSLionel Sambuc struct ToMemPtr { operator DFnPtr(); };
36f4a2713aSLionel Sambuc 
37f4a2713aSLionel Sambuc struct BadDerived;
38f4a2713aSLionel Sambuc struct BadBase { operator BadDerived&(); };
39f4a2713aSLionel Sambuc struct BadDerived : BadBase {};
40f4a2713aSLionel Sambuc 
41f4a2713aSLionel Sambuc struct Fields {
42f4a2713aSLionel Sambuc   int i1, i2, b1 : 3, b2 : 3;
43f4a2713aSLionel Sambuc };
44f4a2713aSLionel Sambuc struct MixedFields {
45f4a2713aSLionel Sambuc   int i;
46f4a2713aSLionel Sambuc   volatile int vi;
47f4a2713aSLionel Sambuc   const int ci;
48f4a2713aSLionel Sambuc   const volatile int cvi;
49f4a2713aSLionel Sambuc };
50f4a2713aSLionel Sambuc struct MixedFieldsDerived : MixedFields {
51f4a2713aSLionel Sambuc };
52f4a2713aSLionel Sambuc 
53f4a2713aSLionel Sambuc enum Enum { EVal };
54f4a2713aSLionel Sambuc 
55f4a2713aSLionel Sambuc struct Ambig {
56f4a2713aSLionel Sambuc   operator short(); // expected-note 2 {{candidate function}}
57f4a2713aSLionel Sambuc   operator signed char(); // expected-note 2 {{candidate function}}
58f4a2713aSLionel Sambuc };
59f4a2713aSLionel Sambuc 
60f4a2713aSLionel Sambuc struct Abstract {
61f4a2713aSLionel Sambuc   virtual ~Abstract() = 0; // expected-note {{unimplemented pure virtual method '~Abstract' in 'Abstract'}}
62f4a2713aSLionel Sambuc };
63f4a2713aSLionel Sambuc 
64f4a2713aSLionel Sambuc struct Derived1: Abstract {
65f4a2713aSLionel Sambuc };
66f4a2713aSLionel Sambuc 
67f4a2713aSLionel Sambuc struct Derived2: Abstract {
68f4a2713aSLionel Sambuc };
69f4a2713aSLionel Sambuc 
test()70f4a2713aSLionel Sambuc void test()
71f4a2713aSLionel Sambuc {
72f4a2713aSLionel Sambuc   // This function tests C++0x 5.16
73f4a2713aSLionel Sambuc 
74f4a2713aSLionel Sambuc   // p1 (contextually convert to bool)
75f4a2713aSLionel Sambuc   int i1 = ToBool() ? 0 : 1;
76f4a2713aSLionel Sambuc 
77f4a2713aSLionel Sambuc   // p2 (one or both void, and throwing)
78*0a6a1f1dSLionel Sambuc   Fields flds;
79f4a2713aSLionel Sambuc   i1 ? throw 0 : throw 1;
80f4a2713aSLionel Sambuc   i1 ? test() : throw 1;
81f4a2713aSLionel Sambuc   i1 ? throw 0 : test();
82f4a2713aSLionel Sambuc   i1 ? test() : test();
83f4a2713aSLionel Sambuc   i1 = i1 ? throw 0 : 0;
84f4a2713aSLionel Sambuc   i1 = i1 ? 0 : throw 0;
85f4a2713aSLionel Sambuc   i1 = i1 ? (throw 0) : 0;
86f4a2713aSLionel Sambuc   i1 = i1 ? 0 : (throw 0);
87f4a2713aSLionel Sambuc   i1 ? 0 : test(); // expected-error {{right operand to ? is void, but left operand is of type 'int'}}
88f4a2713aSLionel Sambuc   i1 ? test() : 0; // expected-error {{left operand to ? is void, but right operand is of type 'int'}}
89*0a6a1f1dSLionel Sambuc   (i1 ? throw 0 : i1) = 0;
90*0a6a1f1dSLionel Sambuc   (i1 ? i1 : throw 0) = 0;
91*0a6a1f1dSLionel Sambuc   (i1 ? (throw 0) : i1) = 0;
92*0a6a1f1dSLionel Sambuc   (i1 ? i1 : (throw 0)) = 0;
93*0a6a1f1dSLionel Sambuc   (i1 ? (void)(throw 0) : i1) = 0; // expected-error {{left operand to ? is void, but right operand is of type 'int'}}
94*0a6a1f1dSLionel Sambuc   (i1 ? i1 : (void)(throw 0)) = 0; // expected-error {{right operand to ? is void, but left operand is of type 'int'}}
95*0a6a1f1dSLionel Sambuc   int &throwRef1 = (i1 ? flds.i1 : throw 0);
96*0a6a1f1dSLionel Sambuc   int &throwRef2 = (i1 ? throw 0 : flds.i1);
97*0a6a1f1dSLionel Sambuc   int &throwRef3 = (i1 ? flds.b1 : throw 0); // expected-error {{non-const reference cannot bind to bit-field}}
98*0a6a1f1dSLionel Sambuc   int &throwRef4 = (i1 ? throw 0 : flds.b1); // expected-error {{non-const reference cannot bind to bit-field}}
99f4a2713aSLionel Sambuc 
100f4a2713aSLionel Sambuc   // p3 (one or both class type, convert to each other)
101f4a2713aSLionel Sambuc   // b1 (lvalues)
102f4a2713aSLionel Sambuc   Base base;
103f4a2713aSLionel Sambuc   Derived derived;
104f4a2713aSLionel Sambuc   Convertible conv;
105f4a2713aSLionel Sambuc   Base &bar1 = i1 ? base : derived;
106f4a2713aSLionel Sambuc   Base &bar2 = i1 ? derived : base;
107f4a2713aSLionel Sambuc   Base &bar3 = i1 ? base : conv;
108f4a2713aSLionel Sambuc   Base &bar4 = i1 ? conv : base;
109f4a2713aSLionel Sambuc   // these are ambiguous
110f4a2713aSLionel Sambuc   BadBase bb;
111f4a2713aSLionel Sambuc   BadDerived bd;
112f4a2713aSLionel Sambuc   (void)(i1 ? bb : bd); // expected-error {{conditional expression is ambiguous; 'BadBase' can be converted to 'BadDerived' and vice versa}}
113f4a2713aSLionel Sambuc   (void)(i1 ? bd : bb); // expected-error {{conditional expression is ambiguous}}
114f4a2713aSLionel Sambuc   // curiously enough (and a defect?), these are not
115f4a2713aSLionel Sambuc   // for rvalues, hierarchy takes precedence over other conversions
116f4a2713aSLionel Sambuc   (void)(i1 ? BadBase() : BadDerived());
117f4a2713aSLionel Sambuc   (void)(i1 ? BadDerived() : BadBase());
118f4a2713aSLionel Sambuc 
119f4a2713aSLionel Sambuc   // b2.1 (hierarchy stuff)
120f4a2713aSLionel Sambuc   extern const Base constret();
121f4a2713aSLionel Sambuc   extern const Derived constder();
122f4a2713aSLionel Sambuc   // should use const overload
123f4a2713aSLionel Sambuc   A a1((i1 ? constret() : Base()).trick());
124f4a2713aSLionel Sambuc   A a2((i1 ? Base() : constret()).trick());
125f4a2713aSLionel Sambuc   A a3((i1 ? constret() : Derived()).trick());
126f4a2713aSLionel Sambuc   A a4((i1 ? Derived() : constret()).trick());
127f4a2713aSLionel Sambuc   // should use non-const overload
128f4a2713aSLionel Sambuc   i1 = (i1 ? Base() : Base()).trick();
129f4a2713aSLionel Sambuc   i1 = (i1 ? Base() : Base()).trick();
130f4a2713aSLionel Sambuc   i1 = (i1 ? Base() : Derived()).trick();
131f4a2713aSLionel Sambuc   i1 = (i1 ? Derived() : Base()).trick();
132f4a2713aSLionel Sambuc   // should fail: const lost
133f4a2713aSLionel Sambuc   (void)(i1 ? Base() : constder()); // expected-error {{incompatible operand types ('Base' and 'const Derived')}}
134f4a2713aSLionel Sambuc   (void)(i1 ? constder() : Base()); // expected-error {{incompatible operand types ('const Derived' and 'Base')}}
135f4a2713aSLionel Sambuc 
136f4a2713aSLionel Sambuc   Priv priv;
137f4a2713aSLionel Sambuc   Fin fin;
138f4a2713aSLionel Sambuc   (void)(i1 ? Base() : Priv()); // expected-error{{private base class}}
139f4a2713aSLionel Sambuc   (void)(i1 ? Priv() : Base()); // expected-error{{private base class}}
140f4a2713aSLionel Sambuc   (void)(i1 ? Base() : Fin()); // expected-error{{ambiguous conversion from derived class 'Fin' to base class 'Base':}}
141f4a2713aSLionel Sambuc   (void)(i1 ? Fin() : Base()); // expected-error{{ambiguous conversion from derived class 'Fin' to base class 'Base':}}
142f4a2713aSLionel Sambuc   (void)(i1 ? base : priv); // expected-error {{private base class}}
143f4a2713aSLionel Sambuc   (void)(i1 ? priv : base); // expected-error {{private base class}}
144f4a2713aSLionel Sambuc   (void)(i1 ? base : fin); // expected-error {{ambiguous conversion from derived class 'Fin' to base class 'Base':}}
145f4a2713aSLionel Sambuc   (void)(i1 ? fin : base); // expected-error {{ambiguous conversion from derived class 'Fin' to base class 'Base':}}
146f4a2713aSLionel Sambuc 
147f4a2713aSLionel Sambuc   // b2.2 (non-hierarchy)
148f4a2713aSLionel Sambuc   i1 = i1 ? I() : i1;
149f4a2713aSLionel Sambuc   i1 = i1 ? i1 : I();
150f4a2713aSLionel Sambuc   I i2(i1 ? I() : J());
151f4a2713aSLionel Sambuc   I i3(i1 ? J() : I());
152f4a2713aSLionel Sambuc   // "the type [it] woud have if E2 were converted to an rvalue"
153f4a2713aSLionel Sambuc   vfn pfn = i1 ? F() : test;
154f4a2713aSLionel Sambuc   pfn = i1 ? test : F();
155f4a2713aSLionel Sambuc   (void)(i1 ? A() : B()); // expected-error {{conversion from 'B' to 'A' is ambiguous}}
156f4a2713aSLionel Sambuc   (void)(i1 ? B() : A()); // expected-error {{conversion from 'B' to 'A' is ambiguous}}
157f4a2713aSLionel Sambuc   (void)(i1 ? 1 : Ambig()); // expected-error {{conversion from 'Ambig' to 'int' is ambiguous}}
158f4a2713aSLionel Sambuc   (void)(i1 ? Ambig() : 1); // expected-error {{conversion from 'Ambig' to 'int' is ambiguous}}
159f4a2713aSLionel Sambuc   // By the way, this isn't an lvalue:
160f4a2713aSLionel Sambuc   &(i1 ? i1 : i2); // expected-error {{cannot take the address of an rvalue}}
161f4a2713aSLionel Sambuc 
162f4a2713aSLionel Sambuc   // p4 (lvalue, same type)
163f4a2713aSLionel Sambuc   int &ir1 = i1 ? flds.i1 : flds.i2;
164f4a2713aSLionel Sambuc   (i1 ? flds.b1 : flds.i2) = 0;
165f4a2713aSLionel Sambuc   (i1 ? flds.i1 : flds.b2) = 0;
166f4a2713aSLionel Sambuc   (i1 ? flds.b1 : flds.b2) = 0;
167f4a2713aSLionel Sambuc 
168f4a2713aSLionel Sambuc   // p5 (conversion to built-in types)
169f4a2713aSLionel Sambuc   // GCC 4.3 fails these
170f4a2713aSLionel Sambuc   double d1 = i1 ? I() : K();
171f4a2713aSLionel Sambuc   pfn = i1 ? F() : G();
172f4a2713aSLionel Sambuc   DFnPtr pfm;
173f4a2713aSLionel Sambuc   pfm = i1 ? DFnPtr() : &Base::fn1;
174f4a2713aSLionel Sambuc   pfm = i1 ? &Base::fn1 : DFnPtr();
175f4a2713aSLionel Sambuc 
176f4a2713aSLionel Sambuc   // p6 (final conversions)
177f4a2713aSLionel Sambuc   i1 = i1 ? i1 : ir1;
178f4a2713aSLionel Sambuc   int *pi1 = i1 ? &i1 : 0;
179f4a2713aSLionel Sambuc   pi1 = i1 ? 0 : &i1;
180f4a2713aSLionel Sambuc   i1 = i1 ? i1 : EVal;
181f4a2713aSLionel Sambuc   i1 = i1 ? EVal : i1;
182f4a2713aSLionel Sambuc   d1 = i1 ? 'c' : 4.0;
183f4a2713aSLionel Sambuc   d1 = i1 ? 4.0 : 'c';
184f4a2713aSLionel Sambuc   Base *pb = i1 ? (Base*)0 : (Derived*)0;
185f4a2713aSLionel Sambuc   pb = i1 ? (Derived*)0 : (Base*)0;
186f4a2713aSLionel Sambuc   pfm = i1 ? &Base::fn1 : &Derived::fn2;
187f4a2713aSLionel Sambuc   pfm = i1 ? &Derived::fn2 : &Base::fn1;
188f4a2713aSLionel Sambuc   pfm = i1 ? &Derived::fn2 : 0;
189f4a2713aSLionel Sambuc   pfm = i1 ? 0 : &Derived::fn2;
190f4a2713aSLionel Sambuc   const int (MixedFieldsDerived::*mp1) =
191f4a2713aSLionel Sambuc     i1 ? &MixedFields::ci : &MixedFieldsDerived::i;
192f4a2713aSLionel Sambuc   const volatile int (MixedFields::*mp2) =
193f4a2713aSLionel Sambuc     i1 ? &MixedFields::ci : &MixedFields::cvi;
194f4a2713aSLionel Sambuc   (void)(i1 ? &MixedFields::ci : &MixedFields::vi);
195f4a2713aSLionel Sambuc   // Conversion of primitives does not result in an lvalue.
196f4a2713aSLionel Sambuc   &(i1 ? i1 : d1); // expected-error {{cannot take the address of an rvalue}}
197f4a2713aSLionel Sambuc 
198f4a2713aSLionel Sambuc   (void)&(i1 ? flds.b1 : flds.i1); // expected-error {{address of bit-field requested}}
199f4a2713aSLionel Sambuc   (void)&(i1 ? flds.i1 : flds.b1); // expected-error {{address of bit-field requested}}
200f4a2713aSLionel Sambuc 
201f4a2713aSLionel Sambuc 
202f4a2713aSLionel Sambuc   unsigned long test0 = 5;
203f4a2713aSLionel Sambuc   test0 = test0 ? (long) test0 : test0; // expected-warning {{operand of ? changes signedness: 'long' to 'unsigned long'}}
204f4a2713aSLionel Sambuc   test0 = test0 ? (int) test0 : test0; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}}
205f4a2713aSLionel Sambuc   test0 = test0 ? (short) test0 : test0; // expected-warning {{operand of ? changes signedness: 'short' to 'unsigned long'}}
206f4a2713aSLionel Sambuc   test0 = test0 ? test0 : (long) test0; // expected-warning {{operand of ? changes signedness: 'long' to 'unsigned long'}}
207f4a2713aSLionel Sambuc   test0 = test0 ? test0 : (int) test0; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}}
208f4a2713aSLionel Sambuc   test0 = test0 ? test0 : (short) test0; // expected-warning {{operand of ? changes signedness: 'short' to 'unsigned long'}}
209f4a2713aSLionel Sambuc   test0 = test0 ? test0 : (long) 10;
210f4a2713aSLionel Sambuc   test0 = test0 ? test0 : (int) 10;
211f4a2713aSLionel Sambuc   test0 = test0 ? test0 : (short) 10;
212f4a2713aSLionel Sambuc   test0 = test0 ? (long) 10 : test0;
213f4a2713aSLionel Sambuc   test0 = test0 ? (int) 10 : test0;
214f4a2713aSLionel Sambuc   test0 = test0 ? (short) 10 : test0;
215f4a2713aSLionel Sambuc 
216f4a2713aSLionel Sambuc   int test1;
217f4a2713aSLionel Sambuc   test0 = test0 ? EVal : test0;
218f4a2713aSLionel Sambuc   test1 = test0 ? EVal : (int) test0;
219f4a2713aSLionel Sambuc 
220f4a2713aSLionel Sambuc   test0 = test0 ? EVal : test1; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}}
221f4a2713aSLionel Sambuc   test0 = test0 ? test1 : EVal; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}}
222f4a2713aSLionel Sambuc 
223f4a2713aSLionel Sambuc   test1 = test0 ? EVal : (int) test0;
224f4a2713aSLionel Sambuc   test1 = test0 ? (int) test0 : EVal;
225f4a2713aSLionel Sambuc 
226f4a2713aSLionel Sambuc   // Note the thing that this does not test: since DR446, various situations
227f4a2713aSLionel Sambuc   // *must* create a separate temporary copy of class objects. This can only
228f4a2713aSLionel Sambuc   // be properly tested at runtime, though.
229f4a2713aSLionel Sambuc 
230*0a6a1f1dSLionel Sambuc   const Abstract &abstract1 = true ? static_cast<const Abstract&>(Derived1()) : Derived2(); // expected-error {{allocating an object of abstract class type 'const Abstract'}}
231*0a6a1f1dSLionel Sambuc   const Abstract &abstract2 = true ? static_cast<const Abstract&>(Derived1()) : throw 3; // ok
232f4a2713aSLionel Sambuc }
233f4a2713aSLionel Sambuc 
234f4a2713aSLionel Sambuc namespace PR6595 {
235f4a2713aSLionel Sambuc   struct OtherString {
236f4a2713aSLionel Sambuc     OtherString();
237f4a2713aSLionel Sambuc     OtherString(const char*);
238f4a2713aSLionel Sambuc   };
239f4a2713aSLionel Sambuc 
240f4a2713aSLionel Sambuc   struct String {
241f4a2713aSLionel Sambuc     String(const char *);
242f4a2713aSLionel Sambuc     String(const OtherString&);
243f4a2713aSLionel Sambuc     operator const char*() const;
244f4a2713aSLionel Sambuc   };
245f4a2713aSLionel Sambuc 
f(bool Cond,String S,OtherString OS)246f4a2713aSLionel Sambuc   void f(bool Cond, String S, OtherString OS) {
247f4a2713aSLionel Sambuc     (void)(Cond? S : "");
248f4a2713aSLionel Sambuc     (void)(Cond? "" : S);
249f4a2713aSLionel Sambuc     const char a[1] = {'a'};
250f4a2713aSLionel Sambuc     (void)(Cond? S : a);
251f4a2713aSLionel Sambuc     (void)(Cond? a : S);
252f4a2713aSLionel Sambuc     (void)(Cond? OS : S);
253f4a2713aSLionel Sambuc   }
254f4a2713aSLionel Sambuc }
255f4a2713aSLionel Sambuc 
256f4a2713aSLionel Sambuc namespace PR6757 {
257f4a2713aSLionel Sambuc   struct Foo1 {
258f4a2713aSLionel Sambuc     Foo1();
259f4a2713aSLionel Sambuc     Foo1(const Foo1&);
260f4a2713aSLionel Sambuc   };
261f4a2713aSLionel Sambuc 
262f4a2713aSLionel Sambuc   struct Foo2 { };
263f4a2713aSLionel Sambuc 
264f4a2713aSLionel Sambuc   struct Foo3 {
265f4a2713aSLionel Sambuc     Foo3();
266f4a2713aSLionel Sambuc     Foo3(Foo3&); // expected-note{{would lose const qualifier}}
267f4a2713aSLionel Sambuc   };
268f4a2713aSLionel Sambuc 
269f4a2713aSLionel Sambuc   struct Bar {
270f4a2713aSLionel Sambuc     operator const Foo1&() const;
271f4a2713aSLionel Sambuc     operator const Foo2&() const;
272f4a2713aSLionel Sambuc     operator const Foo3&() const;
273f4a2713aSLionel Sambuc   };
274f4a2713aSLionel Sambuc 
f()275f4a2713aSLionel Sambuc   void f() {
276f4a2713aSLionel Sambuc     (void)(true ? Bar() : Foo1()); // okay
277f4a2713aSLionel Sambuc     (void)(true ? Bar() : Foo2()); // okay
278f4a2713aSLionel Sambuc     (void)(true ? Bar() : Foo3()); // expected-error{{no viable constructor copying temporary}}
279f4a2713aSLionel Sambuc   }
280f4a2713aSLionel Sambuc }
281f4a2713aSLionel Sambuc 
282f4a2713aSLionel Sambuc // Reduced from selfhost.
283f4a2713aSLionel Sambuc namespace test1 {
284f4a2713aSLionel Sambuc   struct A {
285f4a2713aSLionel Sambuc     enum Foo {
286f4a2713aSLionel Sambuc       fa, fb, fc, fd, fe, ff
287f4a2713aSLionel Sambuc     };
288f4a2713aSLionel Sambuc 
289f4a2713aSLionel Sambuc     Foo x();
290f4a2713aSLionel Sambuc   };
291f4a2713aSLionel Sambuc 
292f4a2713aSLionel Sambuc   void foo(int);
293f4a2713aSLionel Sambuc 
test(A * a)294f4a2713aSLionel Sambuc   void test(A *a) {
295f4a2713aSLionel Sambuc     foo(a ? a->x() : 0);
296f4a2713aSLionel Sambuc   }
297f4a2713aSLionel Sambuc }
298f4a2713aSLionel Sambuc 
299f4a2713aSLionel Sambuc namespace rdar7998817 {
300f4a2713aSLionel Sambuc   class X {
301f4a2713aSLionel Sambuc     X(X&); // expected-note{{declared private here}}
302f4a2713aSLionel Sambuc 
303f4a2713aSLionel Sambuc     struct ref { };
304f4a2713aSLionel Sambuc 
305f4a2713aSLionel Sambuc   public:
306f4a2713aSLionel Sambuc     X();
307f4a2713aSLionel Sambuc     X(ref);
308f4a2713aSLionel Sambuc 
309f4a2713aSLionel Sambuc     operator ref();
310f4a2713aSLionel Sambuc   };
311f4a2713aSLionel Sambuc 
f(bool B)312f4a2713aSLionel Sambuc   void f(bool B) {
313f4a2713aSLionel Sambuc     X x;
314f4a2713aSLionel Sambuc     (void)(B? x // expected-error{{calling a private constructor of class 'rdar7998817::X'}}
315f4a2713aSLionel Sambuc            : X());
316f4a2713aSLionel Sambuc   }
317f4a2713aSLionel Sambuc }
318f4a2713aSLionel Sambuc 
319f4a2713aSLionel Sambuc namespace PR7598 {
320f4a2713aSLionel Sambuc   enum Enum {
321f4a2713aSLionel Sambuc     v = 1,
322f4a2713aSLionel Sambuc   };
323f4a2713aSLionel Sambuc 
g()324f4a2713aSLionel Sambuc   const Enum g() {
325f4a2713aSLionel Sambuc     return v;
326f4a2713aSLionel Sambuc   }
327f4a2713aSLionel Sambuc 
g2()328f4a2713aSLionel Sambuc   const volatile Enum g2() {
329f4a2713aSLionel Sambuc     return v;
330f4a2713aSLionel Sambuc   }
331f4a2713aSLionel Sambuc 
f()332f4a2713aSLionel Sambuc   void f() {
333f4a2713aSLionel Sambuc     const Enum v2 = v;
334f4a2713aSLionel Sambuc     Enum e = false ? g() : v;
335f4a2713aSLionel Sambuc     Enum e2 = false ? v2 : v;
336f4a2713aSLionel Sambuc     Enum e3 = false ? g2() : v;
337f4a2713aSLionel Sambuc   }
338f4a2713aSLionel Sambuc 
339f4a2713aSLionel Sambuc }
340f4a2713aSLionel Sambuc 
341f4a2713aSLionel Sambuc namespace PR9236 {
342f4a2713aSLionel Sambuc #define NULL 0L
f()343f4a2713aSLionel Sambuc   void f() {
344f4a2713aSLionel Sambuc     int i;
345f4a2713aSLionel Sambuc     (void)(true ? A() : NULL); // expected-error{{non-pointer operand type 'A' incompatible with NULL}}
346f4a2713aSLionel Sambuc     (void)(true ? NULL : A()); // expected-error{{non-pointer operand type 'A' incompatible with NULL}}
347f4a2713aSLionel Sambuc     (void)(true ? 0 : A()); // expected-error{{incompatible operand types}}
348f4a2713aSLionel Sambuc     (void)(true ? nullptr : A()); // expected-error{{non-pointer operand type 'A' incompatible with nullptr}}
349f4a2713aSLionel Sambuc     (void)(true ? nullptr : i); // expected-error{{non-pointer operand type 'int' incompatible with nullptr}}
350f4a2713aSLionel Sambuc     (void)(true ? __null : A()); // expected-error{{non-pointer operand type 'A' incompatible with NULL}}
351f4a2713aSLionel Sambuc     (void)(true ? (void*)0 : A()); // expected-error{{incompatible operand types}}
352f4a2713aSLionel Sambuc   }
353f4a2713aSLionel Sambuc }
354f4a2713aSLionel Sambuc 
355f4a2713aSLionel Sambuc namespace DR587 {
356f4a2713aSLionel Sambuc   template<typename T>
f(bool b)357f4a2713aSLionel Sambuc   const T *f(bool b) {
358f4a2713aSLionel Sambuc     static T t1 = T();
359f4a2713aSLionel Sambuc     static const T t2 = T();
360f4a2713aSLionel Sambuc     return &(b ? t1 : t2);
361f4a2713aSLionel Sambuc   }
362f4a2713aSLionel Sambuc   struct S {};
363f4a2713aSLionel Sambuc   template const int *f(bool);
364f4a2713aSLionel Sambuc   template const S *f(bool);
365f4a2713aSLionel Sambuc 
366f4a2713aSLionel Sambuc   extern bool b;
367f4a2713aSLionel Sambuc   int i = 0;
368f4a2713aSLionel Sambuc   const int ci = 0;
369f4a2713aSLionel Sambuc   volatile int vi = 0;
370f4a2713aSLionel Sambuc   const volatile int cvi = 0;
371f4a2713aSLionel Sambuc 
372f4a2713aSLionel Sambuc   const int &cir = b ? i : ci;
373f4a2713aSLionel Sambuc   volatile int &vir = b ? vi : i;
374f4a2713aSLionel Sambuc   const volatile int &cvir1 = b ? ci : cvi;
375f4a2713aSLionel Sambuc   const volatile int &cvir2 = b ? cvi : vi;
376f4a2713aSLionel Sambuc   const volatile int &cvir3 = b ? ci : vi; // expected-error{{volatile lvalue reference to type 'const volatile int' cannot bind to a temporary of type 'int'}}
377f4a2713aSLionel Sambuc }
378*0a6a1f1dSLionel Sambuc 
379*0a6a1f1dSLionel Sambuc namespace PR17052 {
380*0a6a1f1dSLionel Sambuc   struct X {
381*0a6a1f1dSLionel Sambuc     int i_;
382*0a6a1f1dSLionel Sambuc     bool b_;
383*0a6a1f1dSLionel Sambuc 
testPR17052::X384*0a6a1f1dSLionel Sambuc     int &test() { return b_ ? i_ : throw 1; }
385*0a6a1f1dSLionel Sambuc   };
386*0a6a1f1dSLionel Sambuc }
387