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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,b672743914db49f X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wn11feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada From: anon@anon.org (anon) Subject: Re: "Ada Gems": Constructor functions Reply-To: anon@anon.org (anon) References: <1189015827.384331.17490@k79g2000hse.googlegroups.com> X-Newsreader: IBM NewsReader/2 2.0 Message-ID: Date: Thu, 06 Sep 2007 16:16:26 GMT NNTP-Posting-Host: 12.65.174.101 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1189095386 12.65.174.101 (Thu, 06 Sep 2007 16:16:26 GMT) NNTP-Posting-Date: Thu, 06 Sep 2007 16:16:26 GMT Organization: AT&T Worldnet Xref: g2news2.google.com comp.lang.ada:1794 Date: 2007-09-06T16:16:26+00:00 List-Id: Yes, you did find a GNAT BUG! To find the line numbers and errors try gnat1 t.adb -gnatl 2>t.lst gnat1 test_t.adb -gnatl 2>test_t.lst But to make a report to Adacore: First compile using gnatmake test_t.adb 1>1 2>2 -- Note: File '2' should have the error info that Adacore is -- asking about. Then send Adacore the following list of files attach file => t.ads attach file => t.adb attach file => test_t.adb attach file => 1 -- Note: Send File 1 only if it has any special info else skip -- attach file => 2 I use Ada 95 to compile and did not receive the BUG ERROR only a few normal compiling errors. Now, for a compilable corrected version in GNAT Ada 95. Did not use GNAT Ada 2005 compiler. changes to code: --- removed => denote the line is commented out --- Added => denote the line is added to source other comments added for info only ----------- -- t.ads -- ----------- with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; package T is -- type Object (<>) is tagged limited private; --------- removed -------- because can not initial -------- a limited type in Ada 95 type Object (<>) is private; --------- Added function Create_Object (Name : in String) return Object; function Construct return Object; function Name (This : in Object) return String; private ------------------------------ Added -- type Object is tagged limited -------- removed -------- because can not initial -------- a limited type in Ada 95 type Object is ------------------------ Added record Name : Unbounded_String; end record; end T; ----------- -- t.adb -- ----------- package body T is function Create_Object (Name : in String) return Object is begin --------- Added return (Name => To_Unbounded_String (Name)); end Create_Object; function Construct return Object is begin --------- Added return Create_Object (Name => "Object without a name!"); end Construct; function Name (This : in Object) return String is begin return To_String (This.Name); end Name; ---------------------------------------- removed -- ----- because it conflicts -- ----- with t.ads version -- type Object is tagged limited -- record -- Name : Unbounded_String; -- end record; end T; ---------------- -- test_t.ads -- ---------------- with T; use T; ------ Added ------ could of added "T." to Construct instead procedure Test_T is Some_Object : constant T.Object := Construct; begin null; end Test_T; In <1189015827.384331.17490@k79g2000hse.googlegroups.com>, =?iso-8859-2?q?Tomek_Wa=B3kuski?= writes: >Hi, > >motivated by this article posted at adacore.com I have written some >code: > >--------- >t.ads >--------- >with Ada.Strings.Unbounded; >use Ada.Strings.Unbounded; > >package T is > type Object (<>) is tagged limited private; > > function Create_Object (Name : in String) return Object; > function Construct return Object; > function Name (This : in Object) return String; > > type Object is tagged limited > record > Name : Unbounded_String; > end record; >end T; > > >--------- >t.adb >--------- >package body T is > function Create_Object (Name : in String) return Object is > return (Name => To_Unbounded_String (Name)); > end Create_Object; > > function Construct return Object is > return Create_Object (Name => "Object without a name!"); > end Construct; > > function Name (This : in Object) return String is > begin > return To_String (This.Name); > end Name; > > type Object is tagged limited > record > Name : Unbounded_String; > end record; >end T; > > >--------- >test_t.adb >--------- >with T; > >procedure Test_T is > Some_Object : constant T.Object := Construct; >begin > null; >end Test_T; > >------------------------------ >.... and tried to compile it. > >(Gentoo Linux, gnat-gpl-4.1.3.2007) > >Compiler said: >" >+================GNAT BUG DETECTED==================+ >| GPL 2007 (20070402-41) (i686-pc-linux-gnu) Assert_Failure namet.adb: >687 | >(...) >compilation abandoned >gnatmake: "test_t.adb" compilation error >" > >Is it REALLY a compiler bug? Or am I only dumb? :) Maybe I'm doing >something, somewhere wrong? >