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