]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix parsing of raise expressions with no parens
authorPiotr Trojanek <trojanek@adacore.com>
Thu, 2 Jan 2025 16:36:54 +0000 (17:36 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 13 Jan 2025 10:52:56 +0000 (11:52 +0100)
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.

gcc/ada/par-ch4.adb

index 97f9b7ddeb28dfb0a846fce19caed89b1f919fea..3f8d1f1d2e34027ef6f9afdecbe24f9d9f349e7d 100644 (file)
@@ -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