1// PR c++/20280 2 3// { dg-do compile } 4 5// Gimplification of the COND_EXPR used to fail because it had an 6// addressable type, and create_tmp_var rejected that. 7 8struct A 9{ 10 ~A(); 11}; 12 13struct B : A {}; 14 15A& foo(); 16 17void bar(bool b) 18{ 19 (B&) (b ? foo() : foo()); 20} 21 22// Make sure bit-fields and addressable types don't cause crashes. 23// These were not in the original bug report. 24 25// Added by Alexandre Oliva <aoliva@redhat.com> 26 27// Copyright 2005 Free Software Foundation 28 29struct X 30{ 31 long i : 32, j, k : 32; 32}; 33 34void g(long&); 35void h(const long&); 36 37void f(X &x, bool b) 38{ 39 (b ? x.i : x.j) = 1; 40 (b ? x.j : x.k) = 2; 41 (b ? x.i : x.k) = 3; 42 43 (void)(b ? x.i : x.j); 44 (void)(b ? x.i : x.k); 45 (void)(b ? x.j : x.k); 46 47 g (b ? x.i : x.j); // { dg-error "cannot bind bitfield" } 48 g (b ? x.i : x.k); // { dg-error "cannot bind bitfield" } 49 g (b ? x.j : x.k); // { dg-error "cannot bind bitfield" } 50 51 // It's not entirely clear whether these should be accepted. The 52 // conditional expressions are lvalues for sure, and 8.5.3/5 exempts 53 // lvalues for bit-fields, but it's not clear that conditional 54 // expressions that are lvalues and that have at least one possible 55 // result that is a bit-field lvalue meets this condition. 56 h (b ? x.i : x.j); 57 h (b ? x.i : x.k); 58 h (b ? x.j : x.k); 59 60 (long &)(b ? x.i : x.j); // { dg-error "address of bit-field" } 61 (long &)(b ? x.i : x.k); // { dg-error "address of bit-field" } 62 (long &)(b ? x.j : x.k); // { dg-error "address of bit-field" } 63} 64