From: Piotr Trojanek <troja...@adacore.com>

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.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 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 97f9b7ddeb2..3f8d1f1d2e3 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
-- 
2.43.0

Reply via email to