This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Rejection of legal use of subp'Access within a generic body


When the Access attribute is applied within a generic body to a prefix
that denotes a subprogram declared in an enclosing generic unit, the
compiler rejects this as a violation of the rule in the last sentence
of RM 3.10.2(32/3). This is happening because the compiler is requiring
both the access type and subprogram to be declared within the same
enclosing generic unit, but it should be allowing the type to be
anywhere within the declarative part of the generic unit where the
subprogram is declared.

The compiler must issue this output for the test below (based on ACATS B3A2017)
using the command 'gcc -c -gnatd70 generic_subp_access.adb', flagging only
the lines marked 'ERROR':

generic_subp_access.adb:42:22: 'Access attribute not allowed in
                               generic body, because access type
                               "Ref" is declared outside generic unit
                               (RM 3.10.2(32)), move 'Access to
                               private part, or (Ada 2005) use
                               anonymous access type instead of "Ref"
generic_subp_access.adb:44:15: subprogram must not be deeper than
                               access type
generic_subp_access.adb:48:19: 'Access attribute not allowed in
                               generic body, because access type
                               "Ref" is declared outside generic unit
                               (RM 3.10.2(32)), move 'Access to
                               private part, or (Ada 2005) use
                               anonymous access type instead of "Ref"
generic_subp_access.adb:50:12: subprogram must not be deeper than
                               access type

----

procedure Generic_Subp_Access is

   package Pkg is
      type Ref is access procedure;
      P, Q, R : Ref;
   end Pkg;

   generic
     type Formal_Subp_Acc is access procedure;
   package Outer_Generic is

      procedure Foo;

      generic
      package Inner_Generic is

        type Inner_Ref is access procedure;
        Y : Inner_Ref;

      end Inner_Generic;

   end Outer_Generic;

   package body Outer_Generic is
      X : Natural := 0;

      type Local_Ref is access procedure;
      W : Local_Ref;

      V : Formal_Subp_Acc;

      procedure Foo is
      begin
         X := X + 1;
      end Foo;

      package body Inner_Generic is

         M : Formal_Subp_Acc;

      begin
         Pkg.Q := Foo'Access;   -- ERROR
         Y := Foo'Access;       -- OK (was incorrectly flagged as an error)
         M := Foo'Access;       -- ERROR
      end Inner_Generic;

   begin
      Pkg.P := Foo'Access;      -- ERROR
      W := Foo'Access;          -- OK
      V := Foo'Access;          -- ERROR
   end Outer_Generic;

begin
   null;
end Generic_Subp_Access;

Tested on x86_64-pc-linux-gnu, committed on trunk

2015-01-30  Gary Dismukes  <dismukes@adacore.com>

	* sem_attr.adb (Declared_Within_Generic_Unit):
	New function to test whether an entity is declared within the
	declarative region of a given generic unit.
	(Resolve_Attribute): For checking legality of subprogram'Access within
	a generic unit, call new Boolean function Declared_Within_Generic_Unit
	instead of simply comparing the results of Enclosing_Generic_Unit on
	the prefix and access type.  Correct minor comment typos.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]