comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Overriding Default_Component_Value in derived array type
Date: Sat, 25 Apr 2020 00:09:51 +0300
Date: 2020-04-25T00:09:51+03:00	[thread overview]
Message-ID: <hgh2svFi1oqU1@mid.individual.net> (raw)
In-Reply-To: <r7noq1$c5r$1@franka.jacob-sparre.dk>

On 2020-04-22 0:32, Randy Brukardt wrote:
> "Niklas Holsti" <niklas.holsti@tidorum.invalid> wrote in message
> news:hg8rdgFpoa2U1@mid.individual.net...
>> I'm seeing behaviour that looks strange to me when I derive an array type
>> from another and use a Default_Component_Value aspect that tries to
>> override the corresponding aspect of the parent type. The parent's default
>> value is used also for the derived type, that is, the aspect definition
>> for the derived type has no effect, it seems.
>>
>> This is on macOS Mojave (10.14.6), GNAT Community 2019 (20190517-83).
>>
>> An example:
>>
>>        type Number is range 1 .. 15;
>>
>>        type Arr_2 is array (3 .. 5) of Number
>>        with Default_Component_Value => 2;
>>
>>        type Arr_6 is new Arr_2
>>        with Default_Component_Value => 6;
> 
> This is usually illegal by 13.1(10), so it is very rarely done. (If there
> are any subprograms for Arr_2, then Arr_6 is illegal.)

Yes. (Just for the record, I wasn't doing this for a real application,
but to support some discussions I was having about initialization in
various languages -- C, Ada, Java.)

> We're talking about repealing 13.1(10), which will make it more
> necessary for compilers to get this sort of stuff right.
Oh. Sounds complex, if an inherited primitive operation should use the 
default component value of its actual argument type, while sharing code 
with other parent and derived types ... perhaps a hidden parameter would 
be needed?

>> Bug or feature?
> 
> Surely bug.

Thanks. I'll consider submitting a bug report to AdaCore.

> If one didn't give the Default_Component_Value aspect, then of
> course the value would inherit.

Yes, and I saw that happen in another test. Moreover, if I remove the 
parent type's Default_Component_Value aspect, then the aspect in the 
derivation takes effect.

> But be careful that you're not using an inherited routine (that would
> of course use the value for it's own type).
Would that happen (inherited routine using the value for its own type) 
even if you repeal 13.1(10)?

> BTW, my understanding is that AdaCore is reworking Default_Value and
> Default_Component_Value because some silly person (that would be me) wrote a
> bunch of ACATS tests for those aspects. (That's why the request came in to
> repeal 13.1(10)). The next version is likely to be better.

So AdaCore already know about this bug, and perhaps others?

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .

  reply	other threads:[~2020-04-24 21:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-21 18:13 Overriding Default_Component_Value in derived array type Niklas Holsti
2020-04-21 21:32 ` Randy Brukardt
2020-04-24 21:09   ` Niklas Holsti [this message]
2020-04-28  5:43     ` Randy Brukardt
replies disabled

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