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.
This commit is contained in:
Jeff Law 2020-01-30 14:09:41 -07:00
parent 5fb07870fa
commit f9eb0973ed
4 changed files with 25 additions and 1 deletions

View File

@ -1,3 +1,9 @@
2020-01-30 Jeff Law <law@redhat.com>
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 <joseph@codesourcery.com>
PR c/93348

View File

@ -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);

View File

@ -1,3 +1,8 @@
2020-01-30 Jeff Law <law@redhat.com
PR c/88660
* gcc.dg/pr88660.c: New test
2020-01-30 Jakub Jelinek <jakub@redhat.com>
PR lto/93384

View File

@ -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;
}
}