help / color / mirror / Atom feed
* GNAT or Language Problems?
@ 2023-05-30 16:36 Jeffrey R.Carter
  2023-06-17  7:28 ` Randy Brukardt
  0 siblings, 1 reply; 11+ messages in thread
From: Jeffrey R.Carter @ 2023-05-30 16:36 UTC (permalink / raw)

Here are a couple of things that recent versions of GNAT reject, and I suspect 
that these are GNAT errors, but would appreciate input from language lawyers to 
be sure. If they're not GNAT errors, then they seem like things that make Ada 
less easy to use than I'd like.

The first is gcc bug 108157 
( GNAT.Sockets has

package GNAT.Sockets is
    type Selector_Type is limited private;
    procedure Connect_Socket
      (Socket   : Socket_Type;
       Server   : Sock_Addr_Type;
       Timeout  : Selector_Duration;
       Selector : access Selector_Type := null;
       Status   : out Selector_Status);
    --  Connect Socket to the given Server address using Connect_Socket, waiting
    --  no longer than the given timeout duration. Status is set to indicate
    --  whether the operation completed successfully, timed out, or was aborted.
    --  If Selector is not null, the designated selector is used to wait for the
    --  socket to become available, else a private selector object is created
    --  by this procedure and destroyed before it returns. If Timeout is 0.0,
    --  no attempt is made to detect whether the connection has succeeded; it
    --  is up to the user to determine this using Check_Selector later on.
    type Selector_Type (Is_Null : Boolean := False) is limited record
       case Is_Null is
          when True =>

          when False =>
             R_Sig_Socket : Socket_Type := No_Socket;
             W_Sig_Socket : Socket_Type := No_Socket;
             --  Signalling sockets used to abort a select operation
       end case;
    end record;
end GNAT.Sockets;

Kazakov's GNAT.Sockets.Server had (since modified to work with recent versions 
of GNAT)

package GNAT.Sockets.Server is
    type Connections_Server is tagged limited private;
    procedure Do_Connect
      (Listener : in out Connections_Server'Class;
       Client   : in out Connection_Ptr);
    type Connections_Server is tagged limited record
       --  limited because Selector_Type is limited
       Selector : aliased Selector_Type;
    end record;
end GNAT.Sockets.Server;


package body GNAT.Sockets.Server is
    procedure Do_Connect
      (Listener : in out Connections_Server'Class;
       Client   : in out Connection_Ptr)
       Status : Selector_Status;
         (Socket   => Client.Socket,
          Server   => Client.Client_Address,
          Timeout  => 0.0,
          Selector => Listener.Selector'Unchecked_Access,
          Status   => Status);
    end Do_Connect;
end GNAT.Sockets.Server;

Beginning with GNAT 12, the parameter association

    Selector => Listener.Selector'Unchecked_Access,

gives the error

    object subtype must statically match designated subtype

The FSF GNAT maintainers have decided not to change this, citing

         --  Ada 2005 (AI-363): Require static matching when designated
         --  type has discriminants and a constrained partial view, since
         --  in general objects of such types are mutable, so we can't
         --  allow the access value to designate a constrained object
         --  (because access values must be assumed to designate mutable
         --  objects when designated type does not impose a constraint).

I think that those who use anonymous access types get what they deserve, but had 
  the parameter been mode "in out", there would be no problem. I think that 
access parameters should work the same as "in out" parameters as much as possible.

So, GNAT or Ada problem, or is this a reasonable restriction?

The other instance is in PragmARC.B_Strings (

package PragmARC.B_Strings is
    type B_String (Max_Length : Positive := 1024) is tagged limited private;
    -- Default initial value is Null_B_String

    Null_B_String : constant B_String; -- A string of zero characters
private -- PragmARC.B_Strings
    type B_String (Max_Length : Positive := 1024) is tagged limited record
       Len   : Natural := 0;
       Value : String (1 .. Max_Length) := (1 .. Max_Length => ' ');
    end record;

    Null_B_String : constant B_String := (Max_Length => 1, others => <>);
end PragmARC.B_Strings;

Beginning with GNAT 13, an error on the full declaration of the constant says 
that its subtype does not statically match that of the deferred declaration.
A workaround is to explicitly declare the discriminant value on both 
declarations. Probably making the full declaration be (others => <>) would also 

I don't see this in ARM 7.4; only constants of an anonymous access type have to 
statically match. So this is probably a compiler error, but I thought I would 
see what the experts think.

Jeff Carter
"Ada is a management tool. It selects for software
engineers and encourages the hackers to quit."
Robert C. Leif

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

end of thread, other threads:[~2023-06-27 10:16 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-30 16:36 GNAT or Language Problems? Jeffrey R.Carter
2023-06-17  7:28 ` Randy Brukardt
2023-06-17  9:21   ` Jeffrey R.Carter
2023-06-17 17:50     ` Bill Findlay
2023-06-17 20:49       ` Jeffrey R.Carter
2023-06-22  9:51     ` Randy Brukardt
2023-06-22 12:56       ` Jeffrey R.Carter
2023-06-23  9:55         ` Randy Brukardt
2023-06-24 12:23           ` Jeffrey R.Carter
2023-06-26 21:42             ` Randy Brukardt
2023-06-27 10:16               ` Jeffrey R.Carter

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