c++: Fix ICE with loop pragmas at class scope [PR126323]
Prevents C++ compiler ICE by rejecting loop pragmas at class scope.
This commit resolves an internal compiler error (ICE) in the C++ front-end that occurred when GCC loop pragmas were incorrectly processed at class scope. The parser previously rejected these pragmas only at namespace scope, leading to an attempt to parse a loop as a statement within a member declaration context. The fix ensures that loop pragmas are now only accepted in statement contexts, preventing the ICE.
In Details
The cp_parser_pragma function in gcc/cp/parser.cc has been modified to reject GCC loop pragmas when they appear outside of a valid statement context. Previously, it allowed these pragmas in class scope, leading to an incorrect parse state and an ICE due to misinterpreting loop constructs (e.g., for loop initializers) as member declarations. This change enforces stricter pragma placement, fixing PR126323.
- ICE (Internal Compiler Error)
- An unrecoverable error encountered by the compiler during translation. It indicates a bug within the compiler itself, often triggered by complex or unusual code constructs.
- pragma
- A directive embedded in source code that provides information to the compiler, often for optimization, debugging, or specific preprocessor behavior. GCC pragmas are compiler-specific extensions.
- class scope
- The region within a C++ class definition where its members (data and functions) are declared and accessible.
- statement context
- In programming language parsing, a context where a statement (e.g., an assignment, a loop, a conditional) is expected and syntactically valid.