[Ada] Defaults that raise constraint_error

Message ID 20101008101723.GA10314@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Oct. 8, 2010, 10:17 a.m.
When a default value is inserted in a list of actuals, if the default is known
to raise constraint error it is replaced with an explicit raise node and a
warning is emitted. The default value may already be a Raise_Constraint_Error
node for example if it appears in a nested instantiation. In such a case the
node should not be rewritten, to prevent loops in the machinery that removes
warnings from code that is not in the main unit.
No simple example available.

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

2010-10-08  Ed Schonberg  <schonberg@adacore.com>

	* sem_res.adb (Insert_Default): If default value is already a
	raise_constraint_error do not rewrite it as new raise node, to prevent
	infinite loops in the warning removal machinery.


Index: sem_res.adb
--- sem_res.adb	(revision 165104)
+++ sem_res.adb	(working copy)
@@ -3120,8 +3120,12 @@  package body Sem_Res is
          --  If the default expression raises constraint error, then just
          --  silently replace it with an N_Raise_Constraint_Error node,
          --  since we already gave the warning on the subprogram spec.
+         --  If node is already a Raise_Constraint_Error leave as is, to
+         --  prevent loops in the warnings removal machinery.
-         if Raises_Constraint_Error (Actval) then
+         if Raises_Constraint_Error (Actval)
+           and then Nkind (Actval) /= N_Raise_Constraint_Error
+         then
             Rewrite (Actval,
               Make_Raise_Constraint_Error (Loc,
                 Reason => CE_Range_Check_Failed));