Bug 34366 - Legal program rejected, various anonymous access-to-subprogram types, Ada 2005
Summary: Legal program rejected, various anonymous access-to-subprogram types, Ada 2005
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: 4.1.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Samuel Tardieu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-12-06 21:04 UTC by Ludovic Brenta
Modified: 2007-12-09 11:09 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.1.2 4.2.2
Last reconfirmed: 2007-12-07 02:54:43


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ludovic Brenta 2007-12-06 21:04:58 UTC
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.
Comment 1 Samuel Tardieu 2007-12-06 23:35:41 UTC
Confirmed on 4.3.0 20071206
Comment 2 Samuel Tardieu 2007-12-07 02:54:43 UTC
Confirmed on 4.3.0 20071206
Comment 3 Samuel Tardieu 2007-12-09 11:08:06 UTC
Subject: Bug 34366

Author: sam
Date: Sun Dec  9 11:07:54 2007
New Revision: 130720

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130720
Log:
    gcc/ada/
	PR ada/34366
	* sem_ch3.adb (Designates_T): New function.
	(Mentions_T): Factor reusable part of the logic into Designates_T.
	Consider non-access parameters and access and non-access result.
	(Check_Anonymous_Access_Components): Set ekind of anonymous access to
	E_Subprogram_Type to E_Anonymous_Access_Subprogram_Type.

	* einfo.ads: Update comment for E_Anonymous_Access_Subprogram_Type.

    gcc/testsuite/
	PR ada/34366
	* gnat.dg/enclosing_record_reference.ads,
	gnat.dg/enclosing_record_reference.adb: New test.

Added:
    trunk/gcc/testsuite/gnat.dg/enclosing_record_reference.adb
    trunk/gcc/testsuite/gnat.dg/enclosing_record_reference.ads
Modified:
    trunk/gcc/ada/ChangeLog
    trunk/gcc/ada/einfo.ads
    trunk/gcc/ada/sem_ch3.adb
    trunk/gcc/testsuite/ChangeLog

Comment 4 Samuel Tardieu 2007-12-09 11:09:23 UTC
Fixed in SVN trunk