Mark switch expression as used to avoid bogus warning
authorJeff Law <law@redhat.com>
Thu, 30 Jan 2020 21:09:41 +0000 (14:09 -0700)
committerJeff Law <law@redhat.com>
Thu, 30 Jan 2020 21:09:41 +0000 (14:09 -0700)
        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.

gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr88660.c [new file with mode: 0644]

index 9497365a5696e609707a49c294fb2e700f8fd1c6..995f315a8031bab8c6bc03b9ebf4e02a3f8458bc 100644 (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
index 6164017de0269614fb6e1909ccb2ed0d0e1b2885..1e8f2f7108d7c4615d8a2acfcc9ba75a473bf418 100644 (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);
index 4503016a73e6555ed479e47b537ad5be9479aeab..90eb0b2ffba6a6552bde63ae84d892df384cf0ce 100644 (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
diff --git a/gcc/testsuite/gcc.dg/pr88660.c b/gcc/testsuite/gcc.dg/pr88660.c
new file mode 100644 (file)
index 0000000..09a2d32
--- /dev/null
@@ -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;
+       }
+}
+
+