re PR c/81779 (bool define from stdbool.h suppresses -Wdeclaration-after-statement)
authorMarek Polacek <polacek@redhat.com>
Wed, 31 Jan 2018 22:12:46 +0000 (22:12 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Wed, 31 Jan 2018 22:12:46 +0000 (22:12 +0000)
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.

From-SVN: r257271

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

index 52ed9f05e4c7245eb1078a9fea568548e4076ecb..561b58e82da85b69efb0fc6bc623fa608a6c5bdc 100644 (file)
@@ -1,3 +1,9 @@
+2018-01-31  Marek Polacek  <polacek@redhat.com>
+
+       PR c/81779
+       * c-parser.c (c_parser_compound_statement_nostart): Call
+       expansion_point_location_if_in_system_header.
+
 2018-01-17  David Malcolm  <dmalcolm@redhat.com>
 
        PR c++/83814
index 3327dc915e9cbe57b3c12162f33244fc851ea189..5e3512a9127ca163a21b1b3e1e6688e23dbe6f1b 100644 (file)
@@ -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)
index 4dd7c6df7aaa4425ef100e6179e2e180a53f820c..149df85427cce9a4a863c2a4711e5afd01ae3daf 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-31  Marek Polacek  <polacek@redhat.com>
+
+       PR c/81779
+       * gcc.dg/pr81779.c: New test.
+
 2018-01-31  Jakub Jelinek  <jakub@redhat.com>
 
        PR fortran/84116
diff --git a/gcc/testsuite/gcc.dg/pr81779.c b/gcc/testsuite/gcc.dg/pr81779.c
new file mode 100644 (file)
index 0000000..6e79638
--- /dev/null
@@ -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;
+}