package test2 is
  pragma elaborate_body;

    type T is record
        F1: access function(x: integer) return T;
        F2: access function(x: T) return integer;             --??
        F3: access function(x: T) return T;                   --??
        F4: access function(x: integer) return access T;      --??
        F5: access function(x: access T) return integer;
        F6: access function(x: access T) return access T;
        F7: access function(x: T) return access T;            --??
        F8: access function(x: access T) return T;
    end record;

end test2;

package body test2 is

    R: aliased T;

    function F1 (x: integer) return T         is begin return R; end;
    function F2 (x: T) return integer         is begin return 0; end;
    function F3 (x: T) return T               is begin return R; end;
    function F4 (x: integer) return access T  is begin return R'access; end;
    function F5 (x: access T) return integer  is begin return 0; end;
    function F6 (x: access T) return access T is begin return R'access; end;
    function F7 (x: T) return access T        is begin return R'access; end;
    function F8 (x: access T) return T        is begin return R; end;

begin
    R.F1 := F1'Access;
    R.F2 := F2'Access;
    R.F3 := F3'Access;
    R.F4 := F4'Access;
    R.F5 := F5'Access;
    R.F6 := F6'Access;
    R.F7 := F7'Access;
    R.F8 := F8'Access;
end test2;

In both GCC 4.1.2 and 4.2.2 the symptoms are the same:

gnatmake -gnat05 test2
gcc-4.1 -c -gnat05 test2.adb
test2.adb:17:15: expected type access to type derived from "Standard.Integer"
defined at test2.ads:6
test2.adb:17:15: found type access to "f2" defined at line 17
test2.adb:18:15: expected type access to type derived from "t" defined at
test2.ads:7
test2.adb:18:15: found type access to "f3" defined at line 18
test2.adb:19:15: found type access to "f4" defined at line 19
test2.adb:20:15: expected an access type with designated type derived from
"Standard.Integer" defined at test2.ads:4
test2.adb:20:15: found an access type with designated type "F5" defined at line
10
test2.adb:21:15: expected an access type with designated type derived from
access to "t" defined at test2.ads:4
test2.adb:21:15: found an access type with designated type "F6" defined at line
11
test2.adb:22:15: found type access to "f7" defined at line 22
test2.adb:23:15: expected an access type with designated type derived from "t"
defined at test2.ads:4
test2.adb:23:15: found an access type with designated type "F8" defined at line
13
test2.ads:6:32: type declaration cannot refer to itself
test2.ads:7:32: type declaration cannot refer to itself
test2.ads:8:55: type declaration cannot refer to itself
test2.ads:11:32: type declaration cannot refer to itself
test2.ads:11:49: type declaration cannot refer to itself
gnatmake: "test2.adb" compilation error

Note how the assignment to R.F1 gives no error message.

In assignments with error messages, the compiler incorrectly expects the
right-hand side of the assignment to have an access type to the return value of
the function; not the access-to-subprogram type.


-- 
           Summary: Legal program rejected, various anonymous access-to-
                    subprogram types, Ada 2005
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ludovic at ludovic-brenta dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34366

Reply via email to