From: Jeff Law Date: Thu, 30 Jan 2020 21:09:41 +0000 (-0700) Subject: Mark switch expression as used to avoid bogus warning X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f9eb0973edb2b4eed4cdbba7105b8af7afe5b547;p=gcc.git Mark switch expression as used to avoid bogus warning PR c/88660 * c-parser.c (c_parser_switch_statement): Make sure to request marking the switch expr as used. PR c/88660 * gcc.dg/pr88660.c: New test. --- diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 9497365a569..995f315a803 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2020-01-30 Jeff Law + + PR c/88660 + * c-parser.c (c_parser_switch_statement): Make sure to request + marking the switch expr as used. + 2020-01-22 Joseph Myers PR c/93348 diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 6164017de02..1e8f2f7108d 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -6607,7 +6607,7 @@ c_parser_switch_statement (c_parser *parser, bool *if_p) && c_token_starts_typename (c_parser_peek_2nd_token (parser))) explicit_cast_p = true; ce = c_parser_expression (parser); - ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, false); + ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, true); expr = ce.value; /* ??? expr has no valid location? */ parens.skip_until_found_close (parser); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4503016a73e..90eb0b2ffba 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-01-30 Jeff Law PR lto/93384 diff --git a/gcc/testsuite/gcc.dg/pr88660.c b/gcc/testsuite/gcc.dg/pr88660.c new file mode 100644 index 00000000000..09a2d3270bd --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr88660.c @@ -0,0 +1,13 @@ +/* { dg-do-compile } */ +/* { dg-options "-O -Wunused-but-set-variable" } */ + +int main(void) +{ + const int i = 0; + switch(i) + { + default: break; + } +} + +