comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: another way to shoot yourself in the foot?
Date: Fri, 20 Jun 2008 09:12:16 -0700 (PDT)
Date: 2008-06-20T09:12:16-07:00	[thread overview]
Message-ID: <25e91ad7-74ce-4b86-b067-8bde57f34380@t12g2000prg.googlegroups.com> (raw)
In-Reply-To: p7donb2fivf8$.q6ln9ujbcu1l.dlg@40tude.net

On Jun 20, 3:26 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:

> Honestly I have no idea how it is managed on the language level. A limited
> interface can be implemented by a non-limited object. Thus from the
> declaration of a factory function, returning a class-wide of some limited
> interface, the compiler cannot decide whether the result should be in-place
> or not. Therefore, IMO, it must consider the worst case, i.e. an in-place
> "return".
>
> Language lawyers?

Interesting question.  I may have to look through AI's to see if this
case was discussed at all.  However, at first glance, when I look at
the wording in 7.5, it talks about the type of the *expression* that
you're using, not the expected type of the thing you're using it for.
This is true in 7.5(2.1), where it puts restrictions on where
expressions of a limited type may be used, and in 7.5(8.1), where it
says that certain expressions of a limited type (i.e. aggregates and
function calls) must be built in place.

So off the top of my head, I think that if you say

  type Int1 is limited interface;

  type Rec is new Int1 with record  -- not limited!
    ...

  function Func (...) returns Rec is ...;

  Obj : Int1'Class := Func(...);

Since the call to Func is an expression of type Rec, which is not
limited, there's no build-in-place requirement; the fact that Obj's
type is the classwide type for a limited interface isn't relevant to
that rule.  The compiler knows what type Func is, so there's no
"assume-the-worst" issue.  If, instead, we had said

  function Func2 (...) returns Int1'Class is ...;

  Obj : Int1'Class := Func2(...);

Now Func2 needs to be called in such a way that it will build the
result in place; following my previous post, this essentially means
passing the address of Obj to Func2.  But whether Func2 passes this
address on to other functions depends on what the "return" statements
in Func2 look like, and the compiler will make the appropriate
decision at that point.  So I don't think there's any "assume-the-
worst" issue here either.

                            -- Adam



  reply	other threads:[~2008-06-20 16:12 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-20  9:03 another way to shoot yourself in the foot? fedya_fedyakoff
2008-06-20  9:34 ` Dmitry A. Kazakov
2008-06-20  9:48   ` fedya_fedyakoff
2008-06-20 10:01     ` Ludovic Brenta
2008-06-20 10:05 ` christoph.grein
2008-06-20 10:26   ` Dmitry A. Kazakov
2008-06-20 16:12     ` Adam Beneschan [this message]
2008-06-20 15:48   ` Adam Beneschan
2008-06-20 19:27   ` Robert A Duff
2008-06-20 23:37     ` Jeffrey R. Carter
2008-06-21  8:56       ` Dmitry A. Kazakov
2008-06-22 20:44         ` Robert A Duff
2008-06-23  7:49           ` Dmitry A. Kazakov
2008-06-24  4:02             ` george.priv
2008-06-24  7:30               ` Dmitry A. Kazakov
2008-06-24 17:16                 ` Robert A Duff
2008-06-24 19:15                   ` Jeffrey R. Carter
2008-06-24 20:31                     ` Robert A Duff
2008-06-24 20:50                       ` Ludovic Brenta
2008-06-24 23:02                         ` Robert A Duff
2008-06-24 23:42                         ` Georg Bauhaus
2008-06-24 21:24                       ` Jeffrey R. Carter
2008-06-24 23:24                         ` Robert A Duff
2008-06-25 15:07                       ` Adam Beneschan
2008-06-24 14:59             ` Adam Beneschan
2008-06-24 16:41               ` Dmitry A. Kazakov
2008-06-24 17:20                 ` Robert A Duff
2008-06-24 17:52                   ` Dmitry A. Kazakov
2008-06-24 23:35                     ` Georg Bauhaus
2008-06-25  8:09                       ` Dmitry A. Kazakov
2008-06-25 10:32                         ` Georg Bauhaus
2008-06-25 12:06                           ` Dmitry A. Kazakov
2008-06-22 20:37       ` Robert A Duff
2008-06-22 21:25         ` Jeffrey R. Carter
2008-07-04 20:52           ` Colin Paul Gloster
2008-07-04 22:15             ` (see below)
2008-07-05 16:06               ` Colin Paul Gloster
2008-07-05 13:38             ` Gary Scott
2008-07-05 16:42               ` Colin Paul Gloster
2008-07-05 19:00                 ` Gary Scott
2008-07-09 19:39                   ` Colin Paul Gloster
2008-07-09 20:35                     ` Richard Maine
2008-07-09 22:49                       ` Terence
2008-07-10  1:07                         ` Gary Scott
2008-07-10 14:10                       ` Colin Paul Gloster
2008-07-10 14:57                         ` fj
2008-07-10 16:47                           ` Richard Maine
2008-07-10 17:03                         ` Dick Hendrickson
2008-07-10 17:26                           ` Craig Powers
2008-07-10 19:55                             ` James Giles
2008-07-10 20:45                               ` Dick Hendrickson
2008-07-10 21:22                                 ` Richard Maine
2008-07-10 21:29                                   ` Craig Powers
2008-07-10 20:45                               ` Craig Powers
2008-07-10 19:51                           ` James Giles
2008-07-11 15:02                             ` Colin Paul Gloster
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox