From 6e08defbf8aa4bce274e617d823ecd2320b776a1 Mon Sep 17 00:00:00 2001 From: mpolacek Date: Fri, 27 Mar 2015 16:46:44 +0000 Subject: [PATCH] PR c++/65556 * semantics.c (finish_switch_cond): If the unlowered type is not an enum, use the type of the condition. * c-c++-common/pr65556.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@221738 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/semantics.c | 2 ++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/c-c++-common/pr65556.c | 23 +++++++++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/pr65556.c diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index baed6e14732..9a3324fe306 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2015-03-27 Marek Polacek + + PR c++/65556 + * semantics.c (finish_switch_cond): If the unlowered type is not an + enum, use the type of the condition. + 2015-03-27 Jason Merrill PR c++/65509 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index f325e41f417..74af7e842c7 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -1165,6 +1165,8 @@ finish_switch_cond (tree cond, tree switch_stmt) } /* We want unlowered type here to handle enum bit-fields. */ orig_type = unlowered_expr_type (cond); + if (TREE_CODE (orig_type) != ENUMERAL_TYPE) + orig_type = TREE_TYPE (cond); if (cond != error_mark_node) { /* Warn if the condition has boolean value. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c1adea5ff19..a5863094050 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-03-27 Marek Polacek + + PR c++/65556 + * c-c++-common/pr65556.c: New test. + 2015-03-27 Jan Hubicka PR ipa/65600 diff --git a/gcc/testsuite/c-c++-common/pr65556.c b/gcc/testsuite/c-c++-common/pr65556.c new file mode 100644 index 00000000000..c6729a13629 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr65556.c @@ -0,0 +1,23 @@ +/* PR c++/65556 */ +/* { dg-do compile } */ + +struct S +{ + long l: 1; + long l2: 41; + unsigned long ul: 1; + unsigned long ul2: 41; +} s; + +void +fn () +{ + switch (s.l) + case 0:; + switch (s.ul) + case 0:; + switch (s.l2) + case 0:; + switch (s.ul2) + case 0:; +} -- 2.11.4.GIT