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] |
Tested on i686-linux, commited on trunk By default the compiler assumes that an enumeration type with convention C will map to a C enum, and therefore should a size of Integer. However, the user may provide a size clause on the type which must be respected. If the entity being frozen is a subtype, the size clause may be inherited from the parent, and must be respected as well. In either case a warning indicates to the user that the C type must be chosen in accordance to the specified size. Executing: gnatmake -f -q testenum.adb testenum must produce the output: types.ads:7:03: enumeration type with Convention C must have the size of a C int Last = 3 SV = A1 ---- with Ada.Text_IO; package CS_Common_Types is type SVID_Type is (M1, M2, A5, M4, M5, M6, A1, A2, A3, A4); for SVID_Type use (M1 => 1, M2 => 2, A5 => 3, M4 => 4, M5 => 5, M6 => 6, A1 => 7, A2 => 8, A3 => 9, A4 => 10); for SVID_Type'Size use 8; pragma Convention (C, SVID_Type); package SVID_IO is new Ada.Text_IO.Enumeration_IO (SVID_Type); function SVID_String (SVID : SVID_Type) return String; end CS_Common_Types; --- package body CS_Common_Types is function SVID_String (SVID : SVID_Type) return String is begin return ""; end SVID_String; end CS_Common_Types; --- with CS_Common_Types; use CS_Common_Types; with Ada.Text_IO; procedure TestEnum is Last : Natural; Str : String := " A1"; SV : SVID_Type; begin SVID_IO.Get (Str, SV, Last); Ada.Text_IO.Put_Line ("Last = " & Last'Img); -- Outputs 3 as expected Ada.Text_IO.Put_Line ("SV = " & SV'Img); -- Raises exception end TestEnum; 2008-05-20 Ed Schonberg <schonberg@adacore.com> * freeze.adb (Freeze_Enumeration_Type): For a subtype that inherits a foreign convention from its base type, do not set the type to that of integer, because it may inherit a size clause. Warn on a size clause with a size different from that of Integer, if the type has convention C.
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] |