From: jason Date: Mon, 21 Mar 2016 21:13:06 +0000 (+0000) Subject: PR c++/70285 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bf64d98ab39b387d879f03ca7d691015a218821a;p=thirdparty%2Fgcc.git PR c++/70285 * cp-gimplify.c (cp_fold) [COND_EXPR]: Handle bit-fields. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@234384 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index cd98a53b0ac4..3912395c8963 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2016-03-21 Jason Merrill + + PR c++/70285 + * cp-gimplify.c (cp_fold) [COND_EXPR]: Handle bit-fields. + 2016-03-18 Jason Merrill PR c++/70139 diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 6a767fa13a4e..9bf248216b8d 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -2130,6 +2130,12 @@ cp_fold (tree x) else x = fold (x); + /* A COND_EXPR might have incompatible types in branches if one or both + arms are bitfields. If folding exposed such a branch, fix it up. */ + if (TREE_CODE (x) != code) + if (tree type = is_bitfield_expr_with_lowered_type (x)) + x = fold_convert (type, x); + break; case CALL_EXPR: diff --git a/gcc/testsuite/g++.dg/other/bitfield5.C b/gcc/testsuite/g++.dg/other/bitfield5.C new file mode 100644 index 000000000000..b8cd4dd206a3 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/bitfield5.C @@ -0,0 +1,15 @@ +// PR c++/70285 + +int a; + +struct S +{ + int i:8; +} b; + +int +fn1 (bool x) +{ + (&fn1 ? b.i : a) = 42; + return (&fn1 ? b.i : a); +}