]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Better error message if non-Ada2022 code declares No_Return function
authorSteve Baird <baird@adacore.com>
Mon, 30 Jan 2023 23:41:48 +0000 (15:41 -0800)
committerMarc Poulhiès <poulhies@adacore.com>
Mon, 22 May 2023 08:44:08 +0000 (10:44 +0200)
When a feature that is legal in Ada2022 but not in earlier Ada versions
is used, we typically want to call Error_Msg_Ada_2022_Feature in order to
generate an informative message in the error case. Specifying No_Return
for a function (as opposed to a procedure) is no exception to this rule.

gcc/ada/

* sem_prag.adb (Analyze_Pragma): In Check_No_Return, call
Error_Msg_Ada_2022_Feature in the case of a function. Remove code
outside of Check_No_Return that was querying Ada_Version.

gcc/ada/sem_prag.adb

index 6b1f9263f9dba3f4d3ed26c7efe7da03ad2327fb..36c1add5ea4878ecfe0d1b94735db98bfc12ed22 100644 (file)
@@ -20035,7 +20035,11 @@ package body Sem_Prag is
                 N : Node_Id) return Boolean
             is
             begin
-               if Ekind (E) = E_Procedure then
+               if Ekind (E) in E_Function | E_Generic_Function then
+                  Error_Msg_Ada_2022_Feature ("No_Return function", Sloc (N));
+                  return Ada_Version >= Ada_2022;
+
+               elsif Ekind (E) = E_Procedure then
 
                   --  If E is a generic instance, marking it with No_Return
                   --  is forbidden, but having it inherit the No_Return of
@@ -20106,9 +20110,7 @@ package body Sem_Prag is
                   --  Ada 2022 (AI12-0269): A function can be No_Return
 
                   if Ekind (E) in E_Generic_Procedure | E_Procedure
-                    or else (Ada_Version >= Ada_2022
-                              and then
-                             Ekind (E) in E_Generic_Function | E_Function)
+                                   | E_Generic_Function | E_Function
                   then
                      --  Check that the pragma is not applied to a body.
                      --  First check the specless body case, to give a