comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: GCC 11 bug? lawyer needed
Date: Tue, 4 May 2021 22:54:43 -0500	[thread overview]
Message-ID: <s6t4u4$7i8$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: lyh7jjztor.fsf@pushface.org

We spent a lot of time and effort in the ARG talking about this case (see 
AI12-0402-1). The Ada 2012 RM does indeed say this case is illegal. The 
reason is that aliased parameters are designed so that one can return part 
of of them in the return object of the function. And a normal parameter is 
assumed to be local (since its accessibility is unknown) - that means it is 
too local for an aliased parameter of a function that is used in some 
non-local way (including being returned from a non-local function).

However, since one cannot return a part of a parameter for a function that 
returns an elementary type (other than anonymous access returns, which have 
special rules anyway), we added an exception to the rules for that case in 
Ada 202x. (We tried a number of more liberal exceptions, but they were 
complex and had [unlikely] holes.) So the most current rule is that the call 
of P is legal.

That wasn't decided until the December ARG meeting, so it happened after the 
GNATPro 21 release (and I expect that the GNAT CE is derived from that 
version). And I'd guess that in Ada 2012 mode, this check would remain as it 
is (the change was not made retroactively - not sure why).

                             Randy.

"Simon Wright" <simon@pushface.org> wrote in message 
news:lyh7jjztor.fsf@pushface.org...
> This code results in the error shown:
>
>     1. package Aliased_Tagged_Types is
>     2.
>     3.    type T is tagged null record;
>     4.
>     5.    function P (Param : aliased T) return Boolean
>     6.      is (False);
>     7.
>     8.    function F (Param : T) return Boolean
>     9.      is (Param.P);
>                 |
>        >>> actual for explicitly aliased formal is too short lived
>
>    10.
>    11. end Aliased_Tagged_Types;
>
> The compiler code that results in this error is at sem_ch4.adb:1490, and
> was introduced for Ada202x accessibiity checking reasons.
>
>   --  Check whether the formal is aliased and if the accessibility
>   --  level of the actual is deeper than the accessibility level
>   --  of the enclosing subprogam to which the current return
>   --  statement applies.
>
>   [...]
>
>   if Is_Explicitly_Aliased (Form)
>     and then Is_Entity_Name (Act)
>     and then Static_Accessibility_Level
>                (Act, Zero_On_Dynamic_Level)
>                  > Subprogram_Access_Level (Current_Subprogram)
>   then
>      Error_Msg_N ("actual for explicitly aliased formal is too"
>                    & " short lived", Act);
>   end if;
>
> ----
>
> For those interested, this issue affects Alire. 


  reply	other threads:[~2021-05-05  3:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-03 16:08 GCC 11 bug? lawyer needed Simon Wright
2021-05-05  3:54 ` Randy Brukardt [this message]
2021-05-05 10:01   ` AdaMagica
2021-05-05 16:10     ` AdaMagica
2021-05-06  0:39       ` Randy Brukardt
2021-05-06 13:07         ` AdaMagica
2021-05-06 20:02         ` Simon Wright
2021-05-06 20:51           ` Dmitry A. Kazakov
2021-05-06 23:59           ` Randy Brukardt
2021-05-08 10:17             ` Simon Wright
replies disabled

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