diff mbox series

[Ada] No_Return procedures in renaming declarations.

Message ID 20170906100935.GA55016@adacore.com
State New
Headers show
Series [Ada] No_Return procedures in renaming declarations. | expand

Commit Message

Arnaud Charlet Sept. 6, 2017, 10:09 a.m. UTC
This patch implements legality rule in 6.5.1 (7/2): if a renaming as body
completes a nonreturning procedure declaration, the renamed procedure must
be nonreturning as well.  Previously GNAT only produced a warning in such
cases.

Tested in ACATS test B651002.

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

2017-09-06  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch6.adb (Check_Returns): Clean up warnings coming from
	generated bodies for renamings that are completions, when renamed
	procedure is No_Return.
	* sem_ch8.adb (Analyze_Subprogram_Renaming): Implement legality
	rule in 6.5.1 (7/2): if a renaming is a completion of a subprogram
	with No_Return, the renamed entity must be No_Return as well.
diff mbox series

Patch

Index: sem_ch6.adb
===================================================================
--- sem_ch6.adb	(revision 251762)
+++ sem_ch6.adb	(working copy)
@@ -6693,7 +6693,11 @@ 
                   Error_Msg_N
                     ("implied return after this statement "
                      & "would have raised Program_Error", Last_Stm);
-               else
+
+               --  In normal compilation mode, do not warn on a generated
+               --  call (e.g. in the body of a renaming as completion).
+
+               elsif Comes_From_Source (Last_Stm) then
                   Error_Msg_N
                     ("implied return after this statement "
                      & "will raise Program_Error??", Last_Stm);
Index: sem_ch8.adb
===================================================================
--- sem_ch8.adb	(revision 251762)
+++ sem_ch8.adb	(working copy)
@@ -2946,6 +2946,14 @@ 
          Check_Fully_Conformant (New_S, Rename_Spec);
          Set_Public_Status (New_S);
 
+         if No_Return (Rename_Spec)
+            and then not No_Return (Entity (Nam))
+         then
+            Error_Msg_N ("renaming completes a No_Return procedure", N);
+            Error_Msg_N
+              ("\renamed procedure must be nonreturning (RM 6.5.1 (7/2))", N);
+         end if;
+
          --  The specification does not introduce new formals, but only
          --  repeats the formals of the original subprogram declaration.
          --  For cross-reference purposes, and for refactoring tools, we