comp.lang.ada
 help / color / mirror / Atom feed
* GNAT: bug or feature?
@ 2010-03-14 21:16 Damien Carbonne
  2010-03-15  0:49 ` Robert A Duff
  0 siblings, 1 reply; 5+ messages in thread
From: Damien Carbonne @ 2010-03-14 21:16 UTC (permalink / raw)


Hi,

When compiled with GNAT GPL 2009 or GNAT GCC 4.4.1 / Ubuntu 9.10, the 
following code:

---------------------------------------------------
package Pack07 is

    type Base is tagged null record;
    function Create return Base;

    type Derived is new Base with null record;

end Pack07;
---------------------------------------------------

exhibits different compiler reactions depending on used options.

With 'gcc -c -gnat95 pack07.ads', I get:

pack07.ads:6:09: type must be declared abstract or "Create" overridden
pack07.ads:6:09: "Create" has been inherited at line 6
pack07.ads:6:09: "Create" has been inherited from subprogram at line 4

This is what I expect.

With 'gcc -c -gnat05 pack07.ads", the compiler tells nothing and seems 
to generate code.

I find this surprising.
I would consider this is a compiler bug. Is this the case or is it a new 
Ada 2005 feature?
May be it is due to an installation problem, but it would be surprising.

What is your opinion about this behavior?

Regards,
Damien Carbonne



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: GNAT: bug or feature?
  2010-03-14 21:16 GNAT: bug or feature? Damien Carbonne
@ 2010-03-15  0:49 ` Robert A Duff
  2010-03-15 10:05   ` AdaMagica
  0 siblings, 1 reply; 5+ messages in thread
From: Robert A Duff @ 2010-03-15  0:49 UTC (permalink / raw)


Damien Carbonne <damien.carbonne@free.fr> writes:

> I find this surprising.
> I would consider this is a compiler bug. Is this the case or is it a new
> Ada 2005 feature?

It's a new feature of Ada 2005.

- Bob



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: GNAT: bug or feature?
  2010-03-15  0:49 ` Robert A Duff
@ 2010-03-15 10:05   ` AdaMagica
  2010-03-15 20:03     ` Damien Carbonne
  0 siblings, 1 reply; 5+ messages in thread
From: AdaMagica @ 2010-03-15 10:05 UTC (permalink / raw)


> It's a new feature of Ada 2005.

Some detail: Your derived type doesn't add any components, so Create
can be inherited without change.

IN Ada 95, it was felt annoying that even in this case, you have to
override the function. Ada 2005 corrects this.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: GNAT: bug or feature?
  2010-03-15 10:05   ` AdaMagica
@ 2010-03-15 20:03     ` Damien Carbonne
  2010-03-15 21:21       ` Robert A Duff
  0 siblings, 1 reply; 5+ messages in thread
From: Damien Carbonne @ 2010-03-15 20:03 UTC (permalink / raw)


AdaMagica a �crit :
>> It's a new feature of Ada 2005.
> 
> Some detail: Your derived type doesn't add any components, so Create
> can be inherited without change.
> 
> IN Ada 95, it was felt annoying that even in this case, you have to
> override the function. Ada 2005 corrects this.

Thanks (both of you) for explanations.
Indeed, when no new component is added, it seems possible for the 
compiler to automatically generate the required function.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: GNAT: bug or feature?
  2010-03-15 20:03     ` Damien Carbonne
@ 2010-03-15 21:21       ` Robert A Duff
  0 siblings, 0 replies; 5+ messages in thread
From: Robert A Duff @ 2010-03-15 21:21 UTC (permalink / raw)


Damien Carbonne <damien.carbonne@free.fr> writes:

> Thanks (both of you) for explanations.
> Indeed, when no new component is added, it seems possible for the
> compiler to automatically generate the required function.

Exactly.  The compiler generates something like:

   overriding
   function Create return Derived is
   begin
      return (Base'(Create) with null record);
   end Create;

which just returns the same thing as the Base type's Create,
but with the Tag set properly for the Derived type.

By the way, you're slightly misusing the term "base" -- that's
not what it means in Ada.  You could call it Parent.  Or Root.

A "base subtype" is something else.

- Bob



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-03-15 21:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-14 21:16 GNAT: bug or feature? Damien Carbonne
2010-03-15  0:49 ` Robert A Duff
2010-03-15 10:05   ` AdaMagica
2010-03-15 20:03     ` Damien Carbonne
2010-03-15 21:21       ` Robert A Duff

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