This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Better handling of controlled objects in conditional expressions

A call to a function that returns a controlled object generates finalization
actions that must be placed in the code immediately after use of the object.
This patch fixes a bug in the handling of these actions when the context of
the function call is a generated if-expression.


    gnatmake -gnatE -q main

must yield:


with Ada.Text_IO; use Ada.Text_IO;
with Pack;        use Pack;

procedure Main is
   function Factorial (Val : Natural) return Natural is
      if Val > 1 then
         return Factorial (Val - 1) * Val;
         return 1;
      end if;
   end Factorial;

   if Is_Even (Factorial (2))
     or Equal (Left  => New_Ctrl,
               Right => New_Ctrl)
      Put_Line ("True");
      Put_Line ("False");
   end if;
end Main;
with Ada.Finalization; use Ada.Finalization;
package Pack is
   type Ctrl is new Controlled with record
      Id : Natural := 123;
   end record;

   function Equal (Left : Ctrl; Right : Ctrl) return Boolean;
   function Is_Even (Val : Natural) return Boolean;
   function New_Ctrl return Ctrl;
end Pack;
package body Pack is
   function Equal (Left : Ctrl; Right : Ctrl) return Boolean is
      return Left.Id = Right.Id;
   end Equal;

   function Is_Even (Val : Natural) return Boolean is
      return Val / 2 = 0;
   end Is_Even;

   function New_Ctrl return Ctrl is
      Result : Ctrl;
      return Result;
   end New_Ctrl;
end Pack;

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

2013-10-14  Ed Schonberg  <>

	* exp_ch4.adb (Process_Transient_Object): If a transient scope
	has already been created, use the corresponding Node_To_Be_Wrapped
	as the insertion point for the controlled actions.

Attachment: difs
Description: Text document

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]