]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix ICE with loop pragmas at class scope [PR126323]
authorOdysseas Georgoudis <odygrd@hotmail.com>
Fri, 24 Jul 2026 19:17:32 +0000 (15:17 -0400)
committerJason Merrill <jason@redhat.com>
Sun, 26 Jul 2026 14:50:51 +0000 (10:50 -0400)
cp_parser_pragma rejected GCC loop pragmas at namespace scope, but not
at class scope.  Consequently, it attempted to parse the following loop
as a statement while in a member-declaration context, leading to an ICE
when processing the loop initializer.

Accept these pragmas only in statement contexts.

gcc/cp/ChangeLog:

PR c++/126323
* parser.cc (cp_parser_pragma): Reject GCC loop pragmas outside
statement contexts.

gcc/testsuite/ChangeLog:

PR c++/126323
* g++.dg/parse/pr126323.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/parser.cc
gcc/testsuite/g++.dg/parse/pr126323.C [new file with mode: 0644]

index 3f042bec1c66cad21b6e794a7455b1919b06200f..13ebd64c48364afa3675d26244df200fe7f439f4 100644 (file)
@@ -57597,7 +57597,7 @@ cp_parser_pragma (cp_parser *parser, enum pragma_context context, bool *if_p)
            gcc_unreachable ();
        }
 
-       if (context == pragma_external)
+       if (context != pragma_stmt && context != pragma_compound)
          {
            error_at (pragma_tok->location,
                      "%<#pragma GCC %s%> must be inside a function",
diff --git a/gcc/testsuite/g++.dg/parse/pr126323.C b/gcc/testsuite/g++.dg/parse/pr126323.C
new file mode 100644 (file)
index 0000000..2224733
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/126323
+
+class C {
+#pragma GCC novector   // { dg-error "must be inside a function" }
+#pragma GCC unroll(0)  // { dg-error "must be inside a function" }
+#pragma GCC ivdep      // { dg-error "must be inside a function" }
+  for (int i = 0; i < 2; i++)  // { dg-error "expected unqualified-id" }
+                               // { dg-error "does not name a type" "" { target *-*-* } .-1 }
+    ;
+};