https://gcc.gnu.org/g:26b649b2d17dccf0f4c3c048f37c49660aad7f71

commit r15-6850-g26b649b2d17dccf0f4c3c048f37c49660aad7f71
Author: Piotr Trojanek <troja...@adacore.com>
Date:   Thu Jan 2 17:36:54 2025 +0100

    ada: Fix parsing of raise expressions with no parens
    
    According to Ada grammar, raise expression is an expression, but requires
    parens to be a simple_expression. We wrongly classified raise expressions
    as expressions, because we mishandled a global state variable in the parser.
    
    This patch causes some illegal code to be rejected.
    
    gcc/ada/ChangeLog:
    
            * par-ch4.adb (P_Relation): Prevent Expr_Form to be overwritten when
            parsing the raise expression itself.
            (P_Simple_Expression): Fix manipulation of Expr_Form.

Diff:
---
 gcc/ada/par-ch4.adb | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/gcc/ada/par-ch4.adb b/gcc/ada/par-ch4.adb
index 97f9b7ddeb28..3f8d1f1d2e34 100644
--- a/gcc/ada/par-ch4.adb
+++ b/gcc/ada/par-ch4.adb
@@ -2181,8 +2181,9 @@ package body Ch4 is
       --  First check for raise expression
 
       if Token = Tok_Raise then
+         Node1 := P_Raise_Expression;
          Expr_Form := EF_Non_Simple;
-         return P_Raise_Expression;
+         return Node1;
       end if;
 
       --  All other cases
@@ -2415,6 +2416,8 @@ package body Ch4 is
             Node1 := P_Term;
          end if;
 
+         Expr_Form := EF_Simple;
+
          --  In the following, we special-case a sequence of concatenations of
          --  string literals, such as "aaa" & "bbb" & ... & "ccc", with nothing
          --  else mixed in. For such a sequence, we return a tree representing
@@ -2530,11 +2533,6 @@ package body Ch4 is
                end;
             end if;
          end;
-
-         --  All done, we clearly do not have name or numeric literal so this
-         --  is a case of a simple expression which is some other possibility.
-
-         Expr_Form := EF_Simple;
       end if;
 
       --  If all extensions are enabled and we have a deep delta aggregate

Reply via email to