From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,74166d5f7afa0c82,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!news.agarik.com!usenet-fr.net!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Duncan Sands Newsgroups: comp.lang.ada Subject: Return_By_Reference or Return_By_Copy (GNAT bug?) Date: Fri, 31 Dec 2004 12:07:05 +0100 Organization: Cuivre, Argent, Or Message-ID: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: melchior.cuivre.fr.eu.org 1104491243 26790 212.85.156.195 (31 Dec 2004 11:07:23 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Fri, 31 Dec 2004 11:07:23 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: User-Agent: KMail/1.6.2 Content-Disposition: inline X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:7341 Date: 2004-12-31T12:07:05+01:00 Consider the following version of the Rosen trick. Should A_Type be returned by reference or by copy? GNAT 3.15p says: by reference; more recent versions of GNAT say: by copy. My understanding is that it should be by reference, because it has a component R_Type that is a return_by_reference type (R_Type is return_by_reference because the full view is limited private). GNAT 3.15p gives the expected output: Mechanism: 2 <= GNAT specific, means return_by_reference 0 1 1 2 gcc at the pre-ssa tag gives: Mechanism: 1 <= GNAT specific, means return_by_copy 0 0 1 1 Before reporting this bug I would like to be sure that it is one. Language lawyers, please step forwards! Thanks a lot, Duncan. -- B spec -- package B is type A_Type is limited private; function Get_The_A return A_Type; procedure Increment (An_A : A_Type); procedure Print (An_A : A_Type); private type R_Type (An_A : access A_Type) is limited null record; type A_Type is record R : R_Type (A_Type'Access); I : Integer := 0; end record; end; -- B body -- with Ada.Text_IO; use Ada.Text_IO; package body B is The_A : A_Type; function Get_The_A return A_Type is begin return The_A; end; procedure Increment (An_A : A_Type) is begin An_A.R.An_A.I := An_A.R.An_A.I + 1; end; procedure Print (An_A : A_Type) is begin Put_Line (An_A.I'Img); end; end; -- X -- with Ada.Text_IO; use Ada.Text_IO; with B; use B; procedure X is procedure Look is The_A_Reference : A_Type renames Get_The_A; begin Print (The_A_Reference); Increment (The_A_Reference); Print (The_A_Reference); end; begin Put_Line ("Mechanism:" & Integer'Image (Get_The_A'Mechanism_Code)); -- GNAT specific attribute, 1 = by_copy, 2 = by_reference New_Line; Look; New_Line; Look; end;