PR testsuite/86649
[official-gcc.git] / gcc / testsuite / g++.dg / tree-ssa / pr20280.C
blobec4dad70620dcba591e9a960db8d810eba15d1b4
1 // PR c++/20280
3 // { dg-do compile }
5 // Gimplification of the COND_EXPR used to fail because it had an
6 // addressable type, and create_tmp_var rejected that.
8 struct A
10     ~A();
13 struct B : A {};
15 A& foo();
17 void bar(bool b)
19     (B&) (b ? foo() : foo());
22 // Make sure bit-fields and addressable types don't cause crashes.
23 // These were not in the original bug report.
25 // Added by Alexandre Oliva <aoliva@redhat.com>
27 // Copyright 2005 Free Software Foundation
29 struct X
31   long i : 32, j, k : 32;
34 void g(long&);
35 void h(const long&);
37 void f(X &x, bool b)
39   (b ? x.i : x.j) = 1;
40   (b ? x.j : x.k) = 2;
41   (b ? x.i : x.k) = 3;
43   (void)(b ? x.i : x.j);
44   (void)(b ? x.i : x.k);
45   (void)(b ? x.j : x.k);
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" }
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);
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" }