aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2017-08-08 08:55:43 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2017-08-08 08:55:43 +0000
commita5afbdd6559c8689424d5776e45cb77120730f43 (patch)
tree86d8dfb9122f35b5054d9aab949bcea0da4b6552 /gcc
parent314e6352040016aff26cc2cf0b9eb60c40ca859e (diff)
downloadgcc-a5afbdd6559c8689424d5776e45cb77120730f43.zip
gcc-a5afbdd6559c8689424d5776e45cb77120730f43.tar.gz
gcc-a5afbdd6559c8689424d5776e45cb77120730f43.tar.bz2
re PR c++/81607 (Conditional operator: "type mismatch in shift expression" error)
PR c++/81607 * cp-gimplify.c (cp_fold): If folding exposed a branch of a COND_EXPR, convert it to the original type of the COND_EXPR, if they differ. * g++.dg/other/bitfield6.C: New test. From-SVN: r250948
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/cp-gimplify.c6
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/other/bitfield6.C9
4 files changed, 24 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 23f6a1d..9325729 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2017-08-08 Marek Polacek <polacek@redhat.com>
+
+ PR c++/81607
+ * cp-gimplify.c (cp_fold): If folding exposed a branch of
+ a COND_EXPR, convert it to the original type of the COND_EXPR, if
+ they differ.
+
2017-08-08 Martin Liska <mliska@suse.cz>
* call.c: Include header files.
diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index 528e388..4a52aa5 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -2316,9 +2316,9 @@ cp_fold (tree 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);
+ if (TREE_CODE (x) != code
+ && !useless_type_conversion_p (TREE_TYPE (org_x), TREE_TYPE (x)))
+ x = fold_convert (TREE_TYPE (org_x), x);
break;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index c2119f4..e08c2e8 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2017-08-08 Marek Polacek <polacek@redhat.com>
+
+ PR c++/81607
+ * g++.dg/other/bitfield6.C: New test.
+
2017-08-07 Michael Meissner <meissner@linux.vnet.ibm.com>
PR target/81593
diff --git a/gcc/testsuite/g++.dg/other/bitfield6.C b/gcc/testsuite/g++.dg/other/bitfield6.C
new file mode 100644
index 0000000..c1e8a17
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/bitfield6.C
@@ -0,0 +1,9 @@
+// PR c++/81607
+
+int a;
+
+struct b {
+ long c : 32;
+} d;
+
+char f = (903092 ? int(d.c) : 0) << a;