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