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] Legality rules for formal packages with box initialization


AI05-0025 specifies that a formal package is illegal if it includes a named box
initialization for an overloaded formal subprogram. This is an extension of an
existing rule for instantiations.

Compiling proc1.adb in Ada2005 mode  must yield the following:

   proc1.adb:10:05: instantiation abandoned
   proc1.adb:10:49: named association not allowed for overloaded formal
   proc1.adb:15:09: instantiation abandoned
   proc1.adb:16:35: named association not allowed for overloaded formal
   proc1.adb:33:09: instantiation abandoned
   proc1.adb:34:35: named association not allowed for overloaded formal
   proc1.adb:40:09: instantiation abandoned
   proc1.adb:41:35: named association not allowed for overloaded formal

---
procedure Proc1 is
    generic
        type T1 is private;
        type T2 is private;
        with function "=" (Left, Right : T1) return Boolean is <>;
        with function "=" (Left, Right : T2) return Boolean is <>;
    package GP1 is
    end GP1;

    package Inst1 is new GP1 (Integer, Integer, "=" => ">="); --  ERROR

    generic
        type T1 is private;
        type T2 is private;
        with package The_Pak1 is new GP1
             (T1 => T1, T2 => T2, "=" => <>, "=" => <>);     --  ERROR
    package GP2 is end GP2;

    package P is
       type T0 is tagged null record;

       function Func (X, Y : T0) return Boolean;
    end;
    use P;

    package body P is
       function Func (X, Y : T0) return Boolean is begin return False; end;
    end P;

    generic
        type T1 is new T0 with private;
        type T2 is new T0 with private;
        with package The_Pak1 is new GP1
             (T1 => T1, T2 => T2, "=" => Func, "=" => Func);  --  ERROR
    package GP3 is end GP3;

    generic
        type T1 is new T0 with private;
        type T2 is new T0 with private;
        with package The_Pak1 is new GP1
             (T1 => T1, T2 => T2, others => <>);             --  ERROR
    package GP4 is end GP4;

    generic
        type T1 is new T0 with private;
        type T2 is new T0 with private;
        with package The_Pak1 is new GP1 ( T1, T2, Func, Func);  --  OK
    package GP5 is end GP5;

begin
   null;
end;

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

2011-08-04  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch12.adb (Analyze_Associations): New routine
	Check_Overloaded_Formal_Subprogram to reject a formal package when
	there is a named association or a box initialisation for an overloaded
	formal subprogram of the corresponding generic.

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]