[Ada] Accept square brackets for expression functions

Message ID 20220111133242.GA749024@adacore.com
State Committed
Commit 805655c137088519751e4ca18df722355a512d88
Headers
Series [Ada] Accept square brackets for expression functions |

Commit Message

Pierre-Marie de Rodat Jan. 11, 2022, 1:32 p.m. UTC
  Ada RM 6.8 allows an expression function to return an aggregate directly
at the top level (enclosed with either parentheses or square brackets).

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* par-ch6.adb (Scan_Body_Or_Expression_Function): Accept left
	bracket as token to open an expression function.
  

Patch

diff --git a/gcc/ada/par-ch6.adb b/gcc/ada/par-ch6.adb
--- a/gcc/ada/par-ch6.adb
+++ b/gcc/ada/par-ch6.adb
@@ -841,7 +841,14 @@  package body Ch6 is
             begin
                --  Expression_Function case
 
-               if Token = Tok_Left_Paren
+               --  If likely an aggregate, check we are in Ada 2022 mode
+
+               if Token = Tok_Left_Bracket then
+                  Error_Msg_Ada_2022_Feature
+                    ("!aggregates as expression function", Token_Ptr);
+               end if;
+
+               if Token in Tok_Left_Paren | Tok_Left_Bracket
                  or else Likely_Expression_Function
                then
                   --  Check expression function allowed here