Various cases of out-of-order keywords in the definition of a record
were already detected. This adds a similar detection after NULL and
RECORD keywords.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* par-ch3.adb (P_Known_Discriminant_Part_Opt): Reword error
message to benefit from existing codefix.
(P_Record_Definition): Detect out-of-order keywords in record
definition and issue appropriate messages. Other cases are
already caught at appropriate places.
diff --git a/gcc/ada/par-ch3.adb b/gcc/ada/par-ch3.adb
--- a/gcc/ada/par-ch3.adb
+++ b/gcc/ada/par-ch3.adb
@@ -3180,7 +3180,8 @@ package body Ch3 is
Scan;
if Token = Tok_Access then
- Error_Msg_SC ("CONSTANT must appear after ACCESS");
+ Error_Msg_SC -- CODEFIX
+ ("ACCESS must come before CONSTANT");
Set_Discriminant_Type
(Specification_Node,
P_Access_Definition (Not_Null_Present));
@@ -3462,8 +3463,42 @@ package body Ch3 is
-- Error recovery: can raise Error_Resync
function P_Record_Definition return Node_Id is
+
+ procedure Catch_Out_Of_Order_Keywords (Keyword : String);
+ -- Catch ouf-of-order keywords in a record definition
+
+ ---------------------------------
+ -- Catch_Out_Of_Order_Keywords --
+ ---------------------------------
+
+ procedure Catch_Out_Of_Order_Keywords (Keyword : String) is
+ begin
+ loop
+ if Token = Tok_Abstract then
+ Error_Msg_SC -- CODEFIX
+ ("ABSTRACT must come before " & Keyword);
+ Scan; -- past ABSTRACT
+
+ elsif Token = Tok_Tagged then
+ Error_Msg_SC -- CODEFIX
+ ("TAGGED must come before " & Keyword);
+ Scan; -- past TAGGED
+
+ elsif Token = Tok_Limited then
+ Error_Msg_SC -- CODEFIX
+ ("LIMITED must come before " & Keyword);
+ Scan; -- past LIMITED
+
+ else
+ exit;
+ end if;
+ end loop;
+ end Catch_Out_Of_Order_Keywords;
+
Rec_Node : Node_Id;
+ -- Start of processing for P_Record_Definition
+
begin
Inside_Record_Definition := True;
Rec_Node := New_Node (N_Record_Definition, Token_Ptr);
@@ -3472,8 +3507,11 @@ package body Ch3 is
if Token = Tok_Null then
Scan; -- past NULL
+
+ Catch_Out_Of_Order_Keywords ("NULL");
T_Record;
Set_Null_Present (Rec_Node, True);
+ Catch_Out_Of_Order_Keywords ("RECORD");
-- Catch incomplete declaration to prevent cascaded errors, see
-- ACATS B393002 for an example.
@@ -3501,6 +3539,7 @@ package body Ch3 is
Scopes (Scope.Last).Junk := (Token /= Tok_Record);
T_Record;
+ Catch_Out_Of_Order_Keywords ("RECORD");
Set_Component_List (Rec_Node, P_Component_List);