comp.lang.ada
 help / color / mirror / Atom feed
* Contraint error when "out" parameter has incorrect initial content
@ 2013-08-25 14:07 pascal.malaise
  2013-08-25 14:31 ` AdaMagica
  2013-08-25 15:25 ` pascal.malaise
  0 siblings, 2 replies; 5+ messages in thread
From: pascal.malaise @ 2013-08-25 14:07 UTC (permalink / raw)


Hi,
I am wondering if GNAT is correct when raising Constraint_Error in the following case:
procedure Out_Discr is

  type T (B : Boolean := False) is record
    case B is
      when True => null;
      when False => null;
    end case;
  end record;
  subtype Tt is T(True);

  procedure P (V : out Tt) is
  begin
    V := (B => True);
  end P;

  M : T;

begin
  M := (B => False);
  P (M); -- <-- Here
end Out_Discr;

>> raised CONSTRAINT_ERROR : out_discr.adb:20 discriminant check failed
Indeed M is not Tt when calling P, but M is "out" parameter. Shouldn't it be overwritten without any constraint check?

Thank you.

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

* Re: Contraint error when "out" parameter has incorrect initial content
  2013-08-25 14:07 Contraint error when "out" parameter has incorrect initial content pascal.malaise
@ 2013-08-25 14:31 ` AdaMagica
  2013-08-25 14:49   ` Niklas Holsti
  2013-08-25 15:25 ` pascal.malaise
  1 sibling, 1 reply; 5+ messages in thread
From: AdaMagica @ 2013-08-25 14:31 UTC (permalink / raw)


RM 6.4.1(16) A formal parameter of mode in out or out with discriminants is constrained if either its nominal subtype or the actual parameter is constrained.

Thus the compiler may assume that variables supplied to calls already have the correct subtype.

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

* Re: Contraint error when "out" parameter has incorrect initial content
  2013-08-25 14:31 ` AdaMagica
@ 2013-08-25 14:49   ` Niklas Holsti
  2013-08-25 16:47     ` AdaMagica
  0 siblings, 1 reply; 5+ messages in thread
From: Niklas Holsti @ 2013-08-25 14:49 UTC (permalink / raw)


On 13-08-25 17:31 , AdaMagica wrote:
> RM 6.4.1(16) A formal parameter of mode in out or out with
> discriminants is constrained if either its nominal subtype or the
> actual parameter is constrained.
> 
> Thus the compiler may assume that variables supplied to calls already
> have the correct subtype.

In other words, as I understand it, this discriminant-check and
Constraint_Error happen when the parameter is passed into the call,
before the assignment statement in the callee.

The discriminant-check occurs because the formal parameter is
constrained to the subtype with a True discriminant. Since the actual
parameter has a False discriminant, the check fails and Constraint_Error
is raised.

Sloppily said: even if the formal parameter mode is "out", if the formal
constrains the discriminants then the discriminants are "in".

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


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

* Re: Contraint error when "out" parameter has incorrect initial content
  2013-08-25 14:07 Contraint error when "out" parameter has incorrect initial content pascal.malaise
  2013-08-25 14:31 ` AdaMagica
@ 2013-08-25 15:25 ` pascal.malaise
  1 sibling, 0 replies; 5+ messages in thread
From: pascal.malaise @ 2013-08-25 15:25 UTC (permalink / raw)


Thank you very much for the reference to the RM and of the explanation.


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

* Re: Contraint error when "out" parameter has incorrect initial content
  2013-08-25 14:49   ` Niklas Holsti
@ 2013-08-25 16:47     ` AdaMagica
  0 siblings, 0 replies; 5+ messages in thread
From: AdaMagica @ 2013-08-25 16:47 UTC (permalink / raw)


On Sunday, August 25, 2013 4:49:41 PM UTC+2, Niklas Holsti wrote:
> Sloppily said: even if the formal parameter mode is "out", if the formal
> constrains the discriminants then the discriminants are "in".

The discriminants have always been in (as are ranges of arrays). In Ada 83, out parameters were not allowed to be read, but discriminants and bounds of arrays were readable.

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

end of thread, other threads:[~2013-08-25 16:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-25 14:07 Contraint error when "out" parameter has incorrect initial content pascal.malaise
2013-08-25 14:31 ` AdaMagica
2013-08-25 14:49   ` Niklas Holsti
2013-08-25 16:47     ` AdaMagica
2013-08-25 15:25 ` pascal.malaise

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