Version 1.2 of acs/ac-00201.txt

Unformatted version of acs/ac-00201.txt version 1.2
Other versions for file acs/ac-00201.txt

!standard 13.14(5)          10-10-21 AC95-00201/01
!class confirmation 10-10-21
!status received no action 10-10-21
!status received 10-06-10
!subject 'Access on a single task or protected object
!summary
!appendix

!topic Applying representation pragmas to instances
!reference
!from Adam Beneschan 10-05-25
!discussion


I've run into a couple cases in publicly available Ada code that look
something like this:

   function My_Func is new Generic_Plot_Function (My_Function);
   pragma Convention (C, My_Func);

I believe this is illegal (although GNAT lets it slip through),
because Convention is a representation pragma (B.1(28)),
representation pragmas can't be applied to entities that are already
frozen (13.14(19)), and My_Func is frozen as soon as the instantiation
appears since a generic instantiation causes freezing (13.14(5)).  Am
I applying the rules correctly?

Assuming that I am, I think this could be a problem because there
isn't any legal way to do what the user wants to do.  (I can also see
how someone might want to use Export in this situation.)  If this were
a noninstance subprogram with a body, you could of course declare the
subprogram, write the representation item, and then complete the
declaration with a body.  But a declaration can't be completed with an
instantiation, so that doesn't work.  I don't think there's a way to
make a renaming-as-body get the job done, because of the rules in
8.5.4(5).

If it's worthwhile to provide this ability, a solution might be to
change 12.3(12):

   A generic_instantiation declares an instance; it is equivalent to
   the instance declaration (a package_declaration or
   subprogram_declaration) immediately followed by the instance body,
   both at the place of the instantiation.

to something like

   A generic_instantiation declares an instance; it is equivalent to
   the instance declaration (a package_declaration or
   subprogram_declaration), immediately followed by any pragmas [or
   representation items?] that apply to the instance, immediately
   followed by the instance body, both at the place of the
   instantiation.

and then define what pragmas "apply to the instance" for this purpose:
possibly any pragmas that immediately follow the generic_instantiation
and have the name of the instance as one of the pragma parameters?

I realize that this is probably too big a change to be considered for
Ada 2012.

I also realize that this is probably feasible only for implementations
that perform instantiations by macro expansion.  It wouldn't work for
shared-code implementations.  However, I don't think this would be a
problem, since an implementation can reject any representation item
that doesn't make sense in that implementation.

****************************************************************

From: Christoph Grein
Sent: Thursday, May 27, 2010  12:55 AM

>   function My_Func is new Generic_Plot_Function (My_Function);
>   pragma Convention (C, My_Func);
>
> Assuming that I am, I think this could be a problem because there
> isn't any legal way to do what the user wants to do.

Why? Wouldn't a wrapper function do?

function Wrapper return ...;
pragma Convention (C, Wrapper);

function Wrapper return ... is
  function My_Func is new Generic_Plot_Function (My_Function); begin
  return My_Func;
end Wrapper;

****************************************************************

Questions? Ask the ACAA Technical Agent