This fixes one particular instance of the "tokens coming from system headers may
suppress a warning" problem.  While we need a more general solution, for GCC 8
we can at least fix this spot.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2018-01-31  Marek Polacek  <pola...@redhat.com>

        PR c/81779
        * c-parser.c (c_parser_compound_statement_nostart): Call
        expansion_point_location_if_in_system_header.

        * gcc.dg/pr81779.c: New test.

diff --git gcc/c/c-parser.c gcc/c/c-parser.c
index 3327dc915e9..5e3512a9127 100644
--- gcc/c/c-parser.c
+++ gcc/c/c-parser.c
@@ -4975,6 +4975,7 @@ c_parser_compound_statement_nostart (c_parser *parser)
   while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
     {
       location_t loc = c_parser_peek_token (parser)->location;
+      loc = expansion_point_location_if_in_system_header (loc);
       if (c_parser_next_token_is_keyword (parser, RID_CASE)
          || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
          || (c_parser_next_token_is (parser, CPP_NAME)
diff --git gcc/testsuite/gcc.dg/pr81779.c gcc/testsuite/gcc.dg/pr81779.c
index e69de29bb2d..6e796384a67 100644
--- gcc/testsuite/gcc.dg/pr81779.c
+++ gcc/testsuite/gcc.dg/pr81779.c
@@ -0,0 +1,15 @@
+/* PR c/81779 */
+/* { dg-do compile } */
+/* { dg-options "-Wdeclaration-after-statement" } */
+
+#include <stdbool.h>
+
+bool
+f2 (char *p)
+{
+  if (!p)
+    return false;
+
+  bool ret = true; /* { dg-warning "ISO C90 forbids mixed declarations and 
code" } */
+  return ret;
+}

        Marek

Reply via email to