In parent generic declare 
 type Type_T (<>) is tagged private;
and complete it in the private part.
In generic child unit declare
 subtype Subtype_T is One.Type_T;
Then try to use the subtype even with initialization
 I2a : Twoo.Subtype_T := Twoo.Init;
and the compiler says: three.2.ada:15:37: error: invalid constraint: type has 
no discriminant
But declare the subtype anywhere else and all is happy.

-------------------------------------------------------------------------------

Using built-in specs.
Target: i686-pc-cygwin
Configured with: ../gcc-4.0.1/configure --prefix=/a/projects/gcc --enable-
languages=ada,c,c++
Thread model: single
gcc version 4.0.1

Built using CYGWIN on a Windows laptop.

------------------------------------------------------------------------------

lap-43: ls -la
total 8
drwxrwxr-x+  2 geb None    0 Aug 14 13:25 .
drwxrwxrwx+ 12 geb None    0 Aug 14 13:21 ..
-rw-rw-r--   1 geb None 3909 Aug 11 22:29 common.gpr
-rw-rw-r--   1 geb None  239 Aug 11 22:39 one.1.ada
-rw-rw-r--   1 geb None  118 Aug 11 22:42 one.2.ada
-rw-rw-r--   1 geb None  180 Aug 11 22:42 one.two.1.ada
-rw-rw-r--   1 geb None  594 Aug 14 13:25 three.2.ada
lap-44: gnat make -P common.gpr three.2.ada
gcc -c -gnata -gnatE -fstack-check -gnatf -gnatm100 -gnatn -gnato -gnatU \
-gnatwa -gnatwe -gnatwi -gnatwj -gnatwK -gnatwl -Wuninitialized -gnatVa \
-pass-exit-codes -O -g -I- -gnatA -x ada /home/geb/foo.dir/three.2.ada
three.2.ada:15:37: error: invalid constraint: type has no discriminant
gnatmake: "/home/geb/foo.dir/three.2.ada" compilation error
lap-45: 


Line 15 of three.2.ada and line 16 are the same except that line 15 is a
subtype that simply renames the type explicitly named on line 16.  They
should both compile equally well but they don't.  The subtype is declared in
a generic child unit of the generic unit that defines the type.  That seems
to be the key.  If the subtype is declared anywhere else then all works as
expected.  But if declared in the generic child unit then it can't be used.

------------------------------------------------------------------------------
common.gpr
------------------------------------------------------------------------------
project Common is       
    
    for Exec_Dir    use ".";
    for Languages   use ( "Ada" );
    for Object_Dir  use ".";
    for Source_Dirs use (".");

    package Binder is
        for Default_Switches ("Ada")
           use ("-E",               -- store stack backtrace on raise
                "-m50",             -- max errors    
                "-Sin",             -- pragma Initialize_Scalars, use inv. val.
                "-static",          -- use static GNAT runtimes
                "-we",              -- warnings are errors
                "-v"                -- verbose output
               );
    end Binder;

    package Builder is  
        for Default_Switches ("Ada") use ();
        for Global_Configuration_Pragmas use "";
        for Executable_Suffix use "";
    end Builder;

    package Compiler is
        for Default_Switches ("Ada")    
           use (
-- is default   "-c",               -- create .o file
                "-gnata",           -- pragma Assert
                "-gnatE",           -- full elab checks
                "-fstack-check",    -- real stack checking
                "-gnatf",           -- full errors
                "-gnatm100",        -- max errors
                "-gnatn",           -- Allow inlines
                "-gnato",           -- numeric ovfl chk
-- ASIS         "-gnatt",           -- ASIS/tree file
-- annoying     "-gnatu",           -- list unit names
                "-gnatU",           -- errors say error:
--                "-gnatv",           -- verbose on errors and more sigh
-- not on Cygwin "-gnatZ",           -- 0 cost exceptions
                "-gnatwa",          -- all warnings
                "-gnatwe",          -- warning==error
-- does not work well   "-gnatwh",          -- hiding warnings
                "-gnatwi",          -- implem. units
                "-gnatwj",          -- obsolete features
                "-gnatwK",          -- don't bother me about possible constants
                "-gnatwl",          -- elab warnings
                "-Wuninitialized",  -- uninit vars
                "-gnatVa",          -- all validity chks
                "-pass-exit-codes", -- tell me about errors
                "-O",               -- try to optimize some
                "-g"                -- debugging
               );   
        for Local_Configuration_Pragmas use "";
    end Compiler;

    package Cross_Reference is
        for Default_Switches ("Ada")
           use ("-a",               -- do everything, not just locals
                "-d",               -- reference parent types for deriveds
                "-f"                -- output full file paths
--              "-u"                -- only output unused symbols
               );
    end Cross_Reference;

    package Finder is
        for Default_Switches ("Ada")
           use ("-a",               -- do everything, not just locals   
                "-d",               -- reference parent types for deriveds
                "-f");
    end Finder;

    package gnatls is
        for Switches use ("-a",     -- do everything, not just locals
                          "-v"      -- verbose information
                         );
    end gnatls;

    package Linker is
        for Default_Switches ("Ada")
           use (
-- not on Cygwin "-f",               -- put list of files into a file    
                "-g"               -- we want debugging
--                "-v",               -- be very verbose
--                "-v"
               );
    end Linker;

    package Naming is   
        for Casing                  use "lowercase";    
        for Dot_Replacement         use ".";    
        for Spec_Suffix     ("Ada") use ".1.ada";   
        for Body_Suffix     ("Ada") use ".2.ada";   
        for Separate_Suffix         use ".3.ada";
    end Naming;

end Common; 

-- Local Variables:
-- mode: adp-mode
-- End: 

------------------------------------------------------------------------------
one.1.ada
------------------------------------------------------------------------------
generic
    type Int_T is range <>;
package One is

    type Type_T (<>) is tagged private;

    function Init return Type_T;

private

    type Type_T (A : Int_T) is tagged
       record
           B : Int_T;
       end record;

end One;
------------------------------------------------------------------------------
one.2.ada
------------------------------------------------------------------------------
package body One is

    function Init return Type_T is
    begin
        return (A=>1,B=>2);
    end Init;

end One;
------------------------------------------------------------------------------
one.two.1.ada
------------------------------------------------------------------------------
generic
    I : Integer;
package One.Two is

    J : constant Integer := I;
    subtype Subtype_T is One.Type_T;
    function Init return Subtype_T renames One.Init;

end One.Two;
------------------------------------------------------------------------------
three.2.ada
------------------------------------------------------------------------------
with One.Two;
with Ada.Text_Io;
procedure Three is
    package Onee is new One (Integer);
    package Twoo is new Onee.Two (3);
begin

    Ada.Text_Io.Put_Line ("Start");
    declare
        I1 : Onee.Type_T := Onee.Init;
    begin
        Ada.Text_Io.Put_Line ("I1" & Integer'Image(I1'Size));
    end;
    declare
        I2a : Twoo.Subtype_T := Twoo.Init;
        I2b : Onee.Type_T := Twoo.Init;
    begin
        Ada.Text_Io.Put_Line ("I2a" & Integer'Image(I2a'Size));
        Ada.Text_Io.Put_Line ("I2b" & Integer'Image(I2b'Size));
    end;
    Ada.Text_Io.Put_Line ("Finish");

end Three;
------------------------------------------------------------------------------

-- 
           Summary: subtype declared in generic child can't be used, same
                    subtype elsewhere works
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ada
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: garynot at comcast dot net
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet:  i686-pc-cygwin


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

Reply via email to