From: Simon Wright <simon@pushface.org>
Subject: Re: Constructors with multiple inheritance
Date: Wed, 09 Nov 2011 09:00:03 +0000
Date: 2011-11-09T09:00:03+00:00 [thread overview]
Message-ID: <m2obwlbrho.fsf@pushface.org> (raw)
In-Reply-To: 21605158.153.1320805494018.JavaMail.geo-discussion-forums@yqiu15
"Rego, P." <pvrego@gmail.com> 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
next prev parent reply other threads:[~2011-11-09 9:00 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-29 19:40 Constructors with multiple inheritance Rego, P.
2011-09-29 20:20 ` Dmitry A. Kazakov
2011-09-30 3:11 ` Rego, P.
2011-09-30 7:36 ` Dmitry A. Kazakov
2011-09-30 14:04 ` Rego, P.
2011-09-30 16:29 ` Robert A Duff
2011-09-30 19:14 ` Rego, P.
2011-09-30 16:42 ` Dmitry A. Kazakov
2011-09-30 19:42 ` Rego, P.
2011-10-06 12:46 ` Julian Leyh
2011-11-09 2:24 ` Rego, P.
2011-11-09 8:39 ` Dmitry A. Kazakov
2011-11-10 3:47 ` Rego, P.
2011-11-10 7:09 ` AdaMagica
2011-11-10 7:20 ` AdaMagica
2011-11-10 8:35 ` Dmitry A. Kazakov
2011-11-12 15:16 ` Rego, P.
2011-11-12 15:30 ` Rego, P.
2011-11-12 16:28 ` Dmitry A. Kazakov
2011-11-12 17:41 ` Rego, P.
2011-11-10 8:33 ` Simon Wright
2011-11-10 9:01 ` Georg Bauhaus
2011-11-10 9:09 ` Georg Bauhaus
2011-11-10 18:16 ` Jeffrey Carter
2011-11-10 19:39 ` Dmitry A. Kazakov
2011-11-09 9:00 ` Simon Wright [this message]
2011-11-10 3:54 ` Rego, P.
2011-10-07 0:08 ` Shark8
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox