This is the mail archive of the gcc-patches@gcc.gnu.org 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] |
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. Executing: gnatmake -gnatE -q main main must yield: True --- with Ada.Text_IO; use Ada.Text_IO; with Pack; use Pack; procedure Main is function Factorial (Val : Natural) return Natural is begin if Val > 1 then return Factorial (Val - 1) * Val; else return 1; end if; end Factorial; begin if Is_Even (Factorial (2)) or Equal (Left => New_Ctrl, Right => New_Ctrl) then Put_Line ("True"); else 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 begin return Left.Id = Right.Id; end Equal; function Is_Even (Val : Natural) return Boolean is begin return Val / 2 = 0; end Is_Even; function New_Ctrl return Ctrl is Result : Ctrl; begin return Result; end New_Ctrl; end Pack; Tested on x86_64-pc-linux-gnu, committed on trunk 2013-10-14 Ed Schonberg <schonberg@adacore.com> * 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] |