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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5f0f4bfb0467bb19 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.73.233 with SMTP id o9mr1516809pbv.8.1320829209963; Wed, 09 Nov 2011 01:00:09 -0800 (PST) Path: h5ni15884pba.0!nntp.google.com!news2.google.com!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Constructors with multiple inheritance Date: Wed, 09 Nov 2011 09:00:03 +0000 Organization: A noiseless patient Spider Message-ID: References: <11513972.2788.1317325228383.JavaMail.geo-discussion-forums@yqnv12> <1rj1mmkvwud1d.dzqoy4jhdfca$.dlg@40tude.net> <4976045.4489.1317352313370.JavaMail.geo-discussion-forums@yqjw35> <2pu3h5hqltxi$.ze4yrf1f2y8z.dlg@40tude.net> <23774546.1654.1317391464047.JavaMail.geo-discussion-forums@yqnk41> <1gnrks1djlaok.1k0r5f8z9ylfx.dlg@40tude.net> <21605158.153.1320805494018.JavaMail.geo-discussion-forums@yqiu15> Mime-Version: 1.0 Injection-Info: mx04.eternal-september.org; posting-host="dFCm8HWntFqmDIilBLqEJQ"; logging-data="9977"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19I6onJrEPOF03JCGg47pliNY9BRTFh3sM=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (darwin) Cancel-Lock: sha1:6rMu/xcSC9Zefaa+FTaXy4IcaZI= sha1:8dXHgx6Cx3Ldr61y2LyVf06ejOE= Xref: news2.google.com comp.lang.ada:14366 Content-Type: text/plain; charset=us-ascii Date: 2011-11-09T09:00:03+00:00 List-Id: "Rego, P." writes: > procedure Test_Pkg_User is > Test_Obj : Test_Pkg.Test_Class_Ptr; > begin > Test_Obj := Test_Obj.Construct; > Put_Line ("Value = "&Integer'Image (Test_Obj.Info)); > end Test_Pkg_User; > > The message I get is the following: > c:\tst>gnatmake test_pkg_user.adb > gcc -c test_pkg_rev623_user.adb > test_pkg_user.adb:12:16: warning: null value not allowed here > test_pkg_user.adb:12:16: warning: "Constraint_Error" will be raised at run time > gcc -c test_pkg.adb > gnatbind -x test_pkg_user.ali > gnatlink test_pkg_user.ali > > What am I still doing wrong? Thanks again. > > Note: Sure if I put in test_pkg_user.adb > Test_Obj : Test_Pkg.Test_Class_Ptr := new Test_Pkg.Test_Class; > it returns me a build with no warning, but I think this way I allocate > memory twice to the pointer (one in the call new Test_Pkg.Test_Class > and the other in the construct method execution), right? The declaration function Construct (T : access Test_Class) return Test_Class_Ptr; requires T not to be null because of ARM2005 3.10(13.1/2) [1] "In addition, the anonymous access subtype defined by the access_definition for a controlling access parameter (see 3.9.2) excludes null." Of course, as your code stands, even if you changed Construct to function Construct (T : Test_Class_Ptr) return Test_Class_Ptr; the call would fail anyway because you don't check for T being null before saying T_Ptr.Info := T.Info + 1; [1] http://www.adaic.org/resources/add_content/standards/05rm/html/RM-3-10.html