From: Trevor Saunders <tbsaunde+...@tbsaunde.org>

Hi,

not doing $subject caused ICES when we tried to parse statements outside of
functions.  Just copy the similar code for other pragmas that effect
statements.


bootstrapped + regtested x86_64-linux-gnu, ok?

Trev

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f60141d..d9c3ad6 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2015-01-18  Trevor Saunders  <tsaund...@mozilla.com>
+
+       * parser.c (cp_parser_pragma): Check if ivdep pragma is within a
+       function.
+
 2015-01-09  Michael Collison  <michael.colli...@linaro.org>
 
        * call.c: Include hash-set.h, machmode.h, vec.h, double-int.h,
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 3290dfa..4f02a65 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -32202,6 +32202,13 @@ cp_parser_pragma (cp_parser *parser, enum 
pragma_context context)
 
     case PRAGMA_IVDEP:
       {
+       if (context == pragma_external)
+         {
+           error_at (pragma_tok->location,
+                     "%<#pragma GCC ivdep%> must be inside a function");
+           break;
+         }
+
        cp_parser_skip_to_pragma_eol (parser, pragma_tok);
        cp_token *tok;
        tok = cp_lexer_peek_token (the_parser->lexer);
diff --git a/gcc/testsuite/g++.dg/pr60211.C b/gcc/testsuite/g++.dg/pr60211.C
new file mode 100644
index 0000000..f00e644
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr60211.C
@@ -0,0 +1,11 @@
+// { dg-do compile }
+void foo() {}
+int x;
+#pragma GCC ivdep // { dg-error "must be inside a function" }
+for ( ; ) // { dg-error "expected unqualified-id before" }
+  ;
+
+  void baz() {}
+#pragma GCC ivdep // { dg-error "must be inside a function" }
+  for (int x = 0; ) // { dg-error "expected unqualified-id before" }
+  ;
-- 
2.1.4

Reply via email to