This is the mail archive of the 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] Spurious error on component clause in generic unit

In ASIS mode the compiler creates and analyzes instance bodies in generic units
and applies semantic checks on record components. Checks on staticness of
components must not be applied to them, as they would not be in the standard
compilation mode.

The following must compile quietly:

   gcc -c -gnatct p.adb

with Q;

package body P is

   type R is record
      A : T;
   end record
     with Size => 8;

   for R use record
      A at 0 range 0 .. 7;
   end record;

   procedure Do_Something is
      procedure G is new Q.Gen_G (Element_Type => R, Element_Size => 1);
   end Do_Something;

end P;
   type T is (<>);
package P is

   procedure Do_Something;
end P;
with System.Storage_Elements;

package Q is

      type Element_Type is private;
      Element_Size : System.Storage_Elements.Storage_Count;
   procedure Gen_G;

end Q;
with Ada.Unchecked_Conversion;

package body Q is

   procedure Gen_G is
      use type System.Storage_Elements.Storage_Count;

      subtype Elements_As_Storage_Array is
        System.Storage_Elements.Storage_Array (1 .. Element_Size);

      function Convert is new
        Ada.Unchecked_Conversion (Source => Element_Type,
                                  Target => Elements_As_Storage_Array);
      pragma Compile_Time_Error (Element_Size * 8 /= Element_Type'Size,
                                   "Wrong value of Element_Size");
   end Gen_G;

end Q;

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

2014-10-31  Ed Schonberg  <>

	* freeze.adb (Freeze_Record_Type): Do not check component size
	if its type is 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]