comp.lang.ada
 help / color / mirror / Atom feed
* Profile mismatch?
@ 2014-03-13 12:06 Simon Wright
  2014-03-13 14:53 ` adambeneschan
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Wright @ 2014-03-13 12:06 UTC (permalink / raw)


Given the code below

   package Profile is
      type A1 is abstract tagged limited null record;
      procedure P (This : not null access A1);
      type A2 is abstract new A1 with null record;
      procedure P (This : access A2);              -- mismatch
      type T1 is new A1 with null record;
      procedure P (This : access T1);              -- mismatch
      type T2 is new A2 with null record;
      procedure P (This : not null access T2);     -- mismatch
      type T3 is new T2 with null record;
      procedure P (This : access T3);              -- mismatch
   end Profile;

should a compiler recognise the mismatches of the null exclusions where
indicated?

GNAT (4.8, 4.9, GPL 2013) accepts this code without comment. I've seen
very similar cases (structurally, but with many more subprograms) which
GNAT didn't accept, saying

   not subtype conformant with operation inherited at line 42
   type of "This" does not match

I've not yet tried to track this down.

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

* Re: Profile mismatch?
  2014-03-13 12:06 Profile mismatch? Simon Wright
@ 2014-03-13 14:53 ` adambeneschan
  2014-03-13 16:35   ` Simon Wright
  0 siblings, 1 reply; 4+ messages in thread
From: adambeneschan @ 2014-03-13 14:53 UTC (permalink / raw)


On Thursday, March 13, 2014 5:06:40 AM UTC-7, Simon Wright wrote:
> Given the code below
> 
>    package Profile is
>       type A1 is abstract tagged limited null record;
>       procedure P (This : not null access A1);
>       type A2 is abstract new A1 with null record;
>       procedure P (This : access A2);              -- mismatch
>       type T1 is new A1 with null record;
>       procedure P (This : access T1);              -- mismatch
>       type T2 is new A2 with null record;
>       procedure P (This : not null access T2);     -- mismatch
>       type T3 is new T2 with null record;
>       procedure P (This : access T3);              -- mismatch
>    end Profile;
> 
> should a compiler recognise the mismatches of the null exclusions where
> indicated?
> 
> GNAT (4.8, 4.9, GPL 2013) accepts this code without comment. I've seen
> very similar cases (structurally, but with many more subprograms) which
> GNAT didn't accept, saying
> 
>    not subtype conformant with operation inherited at line 42
>    type of "This" does not match
> 
> I've not yet tried to track this down.

All of the access parameters are automatically "not null", because they are controlling parameters; a parameter of type "access T" is a controlling parameter if it's for a primitive subprogram of type T where T is tagged.

In Ada 95, which didn't have "not null", the rules said that parameters in that position were required to be non-null.  When "not null" was added to Ada 2005, the decision was made to allow, but not require, the "not null" on controlling parameters, for backward compatibility.  That's not the case for parameters in other positions, which is why you may see "not subtype conformant" errors.

"Full conformance" requires that the actual presence or absence of "not null" be the same, whether or not the null exclusion is implied.  However, this is needed only in some contexts, such as when a subprogram is declared without a body in one place, and the same subprogram's body appears later.  Overriding doesn't require full conformance, I think; I think it only requires subtype conformance, although I'd have to look it up and I can't do so right now.

                             -- Adam


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

* Re: Profile mismatch?
  2014-03-13 14:53 ` adambeneschan
@ 2014-03-13 16:35   ` Simon Wright
  2014-03-13 17:38     ` adambeneschan
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Wright @ 2014-03-13 16:35 UTC (permalink / raw)


adambeneschan@gmail.com writes:

> On Thursday, March 13, 2014 5:06:40 AM UTC-7, Simon Wright wrote:
>> Given the code below
>> 
>>    package Profile is
>>       type A1 is abstract tagged limited null record;
>>       procedure P (This : not null access A1);
>>       type A2 is abstract new A1 with null record;
>>       procedure P (This : access A2);              -- mismatch
>>       type T1 is new A1 with null record;
>>       procedure P (This : access T1);              -- mismatch
>>       type T2 is new A2 with null record;
>>       procedure P (This : not null access T2);     -- mismatch
>>       type T3 is new T2 with null record;
>>       procedure P (This : access T3);              -- mismatch
>>    end Profile;
>> 
>> should a compiler recognise the mismatches of the null exclusions where
>> indicated?
>> 
>> GNAT (4.8, 4.9, GPL 2013) accepts this code without comment. I've
>> seen very similar cases (structurally, but with many more
>> subprograms) which GNAT didn't accept, saying
>> 
>>    not subtype conformant with operation inherited at line 42
>>    type of "This" does not match
>> 
>> I've not yet tried to track this down.
>
> All of the access parameters are automatically "not null", because
> they are controlling parameters; a parameter of type "access T" is a
> controlling parameter if it's for a primitive subprogram of type T
> where T is tagged.
>
> In Ada 95, which didn't have "not null", the rules said that
> parameters in that position were required to be non-null.  When "not
> null" was added to Ada 2005, the decision was made to allow, but not
> require, the "not null" on controlling parameters, for backward
> compatibility.  That's not the case for parameters in other positions,
> which is why you may see "not subtype conformant" errors.

This is what GNAT is doing (I take it you don't actually mean
"position"; in the first case "access T" had to be non-null in Ada 95,
and in the second case it's non-controlling parameters).

> "Full conformance" requires that the actual presence or absence of
> "not null" be the same, whether or not the null exclusion is implied.
> However, this is needed only in some contexts, such as when a
> subprogram is declared without a body in one place, and the same
> subprogram's body appears later.  Overriding doesn't require full
> conformance, I think; I think it only requires subtype conformance,
> although I'd have to look it up and I can't do so right now.

My code has subtype conformance, I think.

Thanks!

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

* Re: Profile mismatch?
  2014-03-13 16:35   ` Simon Wright
@ 2014-03-13 17:38     ` adambeneschan
  0 siblings, 0 replies; 4+ messages in thread
From: adambeneschan @ 2014-03-13 17:38 UTC (permalink / raw)


On Thursday, March 13, 2014 9:35:40 AM UTC-7, Simon Wright wrote:

> > In Ada 95, which didn't have "not null", the rules said that
> > parameters in that position were required to be non-null.  When "not
> > null" was added to Ada 2005, the decision was made to allow, but not
> > require, the "not null" on controlling parameters, for backward
> > compatibility.  That's not the case for parameters in other positions,
> > which is why you may see "not subtype conformant" errors.
> 
> This is what GNAT is doing (I take it you don't actually mean
> "position"; in the first case "access T" had to be non-null in Ada 95,
> and in the second case it's non-controlling parameters).

"Situation" might have been a better word.  In any case, by "parameters in other positions" I meant "non-controlling parameters".  And you're right that all access parameters were non-null in Ada 95, which I forgot, but only the controlling parameters are now implicitly null-excluding if there is no explicit "not null".

                          -- Adam


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

end of thread, other threads:[~2014-03-13 17:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-13 12:06 Profile mismatch? Simon Wright
2014-03-13 14:53 ` adambeneschan
2014-03-13 16:35   ` Simon Wright
2014-03-13 17:38     ` adambeneschan

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