comp.lang.ada
 help / color / mirror / Atom feed
* GNAT CE 2020 : error when using anon access to subprogram inside protected !?
@ 2020-06-02  9:46 Jérôme Haguet
  2020-06-02 12:04 ` Simon Wright
  2020-06-02 13:51 ` J-P. Rosen
  0 siblings, 2 replies; 8+ messages in thread
From: Jérôme Haguet @ 2020-06-02  9:46 UTC (permalink / raw)


Hello 

When I start testing existing code with GNAT CE 2020, I faced a compilation error when using anonymous access to subprogram inside protected body.

Maybe somebody can provide an explanation ...

Hereafter you will find the compiler message and (simplified) code that illustrates my problem 


pb20200602.adb:27:18: subprogram "Do_On_Item" has wrong convention
pb20200602.adb:27:18: does not match access to subprogram declared at line 7


package Pb20200602 is
   protected Tokens is 
      procedure Call_Walker;    
   end;
end;

--  ---------------------------------------------------------------------
with Ada.Text_Io;
package body Pb20200602 is

   protected body Tokens is

      procedure Walker
        (On_Item : not null access procedure (Name    : String);
         Success : out Boolean
        )
      is
      begin
         On_Item.all ("John Doe");
         On_Item.all ("Jane Doe");
         Success := True;
      end;

      procedure Call_Walker
      is
         procedure Do_On_Item (Name      : String)
         is
         begin
            null;
         end;
         Success : Boolean := False;
      begin
         Walker (Do_On_Item'Access,
                 Success);
         if Success then
            Ada.Text_Io.Put_Line ("Success!");
         end if;
      end;

   end;

end;




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

* Re: GNAT CE 2020 : error when using anon access to subprogram inside protected !?
  2020-06-02  9:46 GNAT CE 2020 : error when using anon access to subprogram inside protected !? Jérôme Haguet
@ 2020-06-02 12:04 ` Simon Wright
  2020-06-03  6:36   ` Simon Wright
  2020-06-02 13:51 ` J-P. Rosen
  1 sibling, 1 reply; 8+ messages in thread
From: Simon Wright @ 2020-06-02 12:04 UTC (permalink / raw)


Jérôme Haguet <j.haguet@cadwin.com> writes:

> When I start testing existing code with GNAT CE 2020, I faced a
> compilation error when using anonymous access to subprogram inside
> protected body.

> pb20200602.adb:27:18: subprogram "Do_On_Item" has wrong convention
> pb20200602.adb:27:18: does not match access to subprogram declared at line 7
>
>
> package Pb20200602 is
>    protected Tokens is 
>       procedure Call_Walker;    
>    end;
> end;
>
> --  ---------------------------------------------------------------------
> with Ada.Text_Io;
> package body Pb20200602 is
>
>    protected body Tokens is
>
>       procedure Walker
>         (On_Item : not null access procedure (Name    : String);
>          Success : out Boolean
>         )
>       is
>       begin
>          On_Item.all ("John Doe");
>          On_Item.all ("Jane Doe");
>          Success := True;
>       end;
>
>       procedure Call_Walker
>       is
>          procedure Do_On_Item (Name      : String)
>          is
>          begin
>             null;
>          end;
>          Success : Boolean := False;
>       begin
>          Walker (Do_On_Item'Access,
>                  Success);
>          if Success then
>             Ada.Text_Io.Put_Line ("Success!");
>          end if;
>       end;
>
>    end;
>
> end;

I'm amazed that you can declare Walker inside the PO!

CE 2020 will compile this without complaint if you move Walker outside
the PO.

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

* Re: GNAT CE 2020 : error when using anon access to subprogram inside protected !?
  2020-06-02  9:46 GNAT CE 2020 : error when using anon access to subprogram inside protected !? Jérôme Haguet
  2020-06-02 12:04 ` Simon Wright
@ 2020-06-02 13:51 ` J-P. Rosen
  2020-06-02 14:37   ` Simon Wright
  2020-06-02 18:02   ` AdaMagica
  1 sibling, 2 replies; 8+ messages in thread
From: J-P. Rosen @ 2020-06-02 13:51 UTC (permalink / raw)


Le 02/06/2020 à 11:46, Jérôme Haguet a écrit :
> pb20200602.adb:27:18: subprogram "Do_On_Item" has wrong convention
> pb20200602.adb:27:18: does not match access to subprogram declared at line 7
> 
> 
shouldn't it be access protected procedure ?

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

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

* Re: GNAT CE 2020 : error when using anon access to subprogram inside protected !?
  2020-06-02 13:51 ` J-P. Rosen
@ 2020-06-02 14:37   ` Simon Wright
  2020-06-02 14:55     ` Dmitry A. Kazakov
  2020-06-02 18:02   ` AdaMagica
  1 sibling, 1 reply; 8+ messages in thread
From: Simon Wright @ 2020-06-02 14:37 UTC (permalink / raw)


"J-P. Rosen" <rosen@adalog.fr> writes:

> Le 02/06/2020 à 11:46, Jérôme Haguet a écrit :
>> pb20200602.adb:27:18: subprogram "Do_On_Item" has wrong convention
>> pb20200602.adb:27:18: does not match access to subprogram declared at line 7
>>
>>
> shouldn't it be access protected procedure ?

I wondered that; now both GCC 10 and GNAT CE 2020 complain!

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

* Re: GNAT CE 2020 : error when using anon access to subprogram inside protected !?
  2020-06-02 14:37   ` Simon Wright
@ 2020-06-02 14:55     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 8+ messages in thread
From: Dmitry A. Kazakov @ 2020-06-02 14:55 UTC (permalink / raw)


On 02/06/2020 16:37, Simon Wright wrote:
> "J-P. Rosen" <rosen@adalog.fr> writes:
> 
>> Le 02/06/2020 à 11:46, Jérôme Haguet a écrit :
>>> pb20200602.adb:27:18: subprogram "Do_On_Item" has wrong convention
>>> pb20200602.adb:27:18: does not match access to subprogram declared at line 7
>>>
>>>
>> shouldn't it be access protected procedure ?
> 
> I wondered that; now both GCC 10 and GNAT CE 2020 complain!

Though GCC 10 still does not complain about anonymous access to X'Access 
comparisons, what GNAT CE 2020 does. It seems that this change did not 
hit GCC 10, yet. That will break a lot of code...

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

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

* Re: GNAT CE 2020 : error when using anon access to subprogram inside protected !?
  2020-06-02 13:51 ` J-P. Rosen
  2020-06-02 14:37   ` Simon Wright
@ 2020-06-02 18:02   ` AdaMagica
  1 sibling, 0 replies; 8+ messages in thread
From: AdaMagica @ 2020-06-02 18:02 UTC (permalink / raw)


Am Dienstag, 2. Juni 2020 15:51:02 UTC+2 schrieb J-P. Rosen:
> shouldn't it be access protected procedure ?

Hm, Do_on_Item is internal to the protected procedure Call_Walker, so I thought it's a normal procedure call inside a protected call. And so is Walker.
But I didn't check this in the RM.

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

* Re: GNAT CE 2020 : error when using anon access to subprogram inside protected !?
  2020-06-02 12:04 ` Simon Wright
@ 2020-06-03  6:36   ` Simon Wright
  2020-06-03  9:54     ` J-P. Rosen
  0 siblings, 1 reply; 8+ messages in thread
From: Simon Wright @ 2020-06-03  6:36 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

> I'm amazed that you can declare Walker inside the PO!

9.4(8) allows this. It's always been a gripe of mine that you can't
declare objects (let alone types!) inside a PO's body.

> CE 2020 will compile this without complaint if you move Walker outside
> the PO.

I think that GNAT has become confused about Walker's status: it is a
subprogram_body, but because it's inside a PO it's also a
protected_operation_item.

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

* Re: GNAT CE 2020 : error when using anon access to subprogram inside protected !?
  2020-06-03  6:36   ` Simon Wright
@ 2020-06-03  9:54     ` J-P. Rosen
  0 siblings, 0 replies; 8+ messages in thread
From: J-P. Rosen @ 2020-06-03  9:54 UTC (permalink / raw)


Le 03/06/2020 à 08:36, Simon Wright a écrit :
> 9.4(8) allows this. It's always been a gripe of mine that you can't
> declare objects (let alone types!) inside a PO's body.

Dispite a PO looking like a task or package, it is fundamentally a data
structure, with operations attached. Our beloved separation of
specification and body means that as soon as you have seen a PO's
specification, you must be able to allocate its space => you cannot have
data in the body. QED.

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

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

end of thread, other threads:[~2020-06-03  9:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-02  9:46 GNAT CE 2020 : error when using anon access to subprogram inside protected !? Jérôme Haguet
2020-06-02 12:04 ` Simon Wright
2020-06-03  6:36   ` Simon Wright
2020-06-03  9:54     ` J-P. Rosen
2020-06-02 13:51 ` J-P. Rosen
2020-06-02 14:37   ` Simon Wright
2020-06-02 14:55     ` Dmitry A. Kazakov
2020-06-02 18:02   ` AdaMagica

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