https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62042
Bug ID: 62042 Summary: Missing optimization of copying non-limited objects Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: ada Assignee: unassigned at gcc dot gnu.org Reporter: porton at narod dot ru The below program, compiled with GNAT 4.9, calls Adjust two times when copying a T1 object. But it does the same operations with a T2 object without calling Adjust. So calling Adjust on a T1 object is here redundant and can be optimized away for greater performance. Ada Reference Manual allows this kind of optimization. So GNAT is not as good as I expected, isn't it? with Ada.Finalization; with Ada.Text_IO; procedure Main is type T1 is new Ada.Finalization.Controlled with null record; type T2 is new Ada.Finalization.Limited_Controlled with null record; overriding procedure Adjust(Object: in out T1) is begin Ada.Text_IO.Put_Line("Adjust"); end; function F return T1 is begin return (Ada.Finalization.Controlled with null record); end; function F return T2 is begin return (Ada.Finalization.Limited_Controlled with null record); end; X: T1 := F; Y: T2 := F; begin null; end;