re PR c/28280 (bogus "statement with no effect" warning with VLA and typeof)
authorMike Stump <mrs@apple.com>
Tue, 15 Aug 2006 18:01:19 +0000 (18:01 +0000)
committerMike Stump <mrs@gcc.gnu.org>
Tue, 15 Aug 2006 18:01:19 +0000 (18:01 +0000)
PR c/28280
* c-parser.c (c_parser_typeof_specifier): Don't use
c_finish_expr_stmt, open code desired semantics instead.

From-SVN: r116163

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

index 7caf0883f3d5310a5e07113d59f30bd45ef4a50a..218be9772081661dde7605714692527a434d3e7c 100644 (file)
@@ -1,3 +1,9 @@
+2006-07-15  Mike Stump  <mrs@apple.com>
+
+       PR c/28280
+       * c-parser.c (c_parser_typeof_specifier): Don't use
+       c_finish_expr_stmt, open code desired semantics instead.
+
 2006-08-15  Nick Clifton  <nickc@redhat.com>
 
        * config.gcc (x86-mingw32): Add a gthr-win32.h including makefile
index 848da6305dccdf7cb1ea4cf154607afb7666d4e2..6e243dff58a5d000cdaed0512e4c984349470f2b 100644 (file)
@@ -2164,7 +2164,19 @@ c_parser_typeof_specifier (c_parser *parser)
         is evaluated, this can be evaluated.  For now, we avoid
         evaluation when the context might.  */
       if (!skip_evaluation && was_vm)
-       c_finish_expr_stmt (expr.value);
+       {
+         tree e = expr.value;
+
+         /* If the expression is not of a type to which we cannot assign a line
+            number, wrap the thing in a no-op NOP_EXPR.  */
+         if (DECL_P (e) || CONSTANT_CLASS_P (e))
+           e = build1 (NOP_EXPR, void_type_node, e);
+
+         if (EXPR_P (e))
+           SET_EXPR_LOCATION (e, input_location);
+
+         add_stmt (e);
+       }
       pop_maybe_used (was_vm);
     }
   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
diff --git a/gcc/testsuite/gcc.dg/vla-9.c b/gcc/testsuite/gcc.dg/vla-9.c
new file mode 100644 (file)
index 0000000..0b623b3
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile  } */
+/* { dg-options "-std=c99 -pedantic-errors -W -Wall" } */
+/* PR c/28280 */
+
+void f(__SIZE_TYPE__ d)
+{
+  typedef int t[d];
+  t *g = (__typeof (g)) d;
+}