From: Damien Carbonne on
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
From: Robert A Duff on
Damien Carbonne <damien.carbonne(a)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
From: AdaMagica on
> 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.
From: Damien Carbonne on
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.
From: Robert A Duff on
Damien Carbonne <damien.carbonne(a)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