From: Ed Schonberg Date: Tue, 20 May 2008 12:46:54 +0000 (+0200) Subject: 2008-05-20 Ed Schonberg X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d677afa9583e31ef0eae98998b29f884fd409d72;p=gcc.git 2008-05-20 Ed Schonberg * 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. From-SVN: r135628 --- diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index f2bd7b13b67..21b1ad5884c 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -3828,12 +3828,36 @@ package body Freeze is procedure Freeze_Enumeration_Type (Typ : Entity_Id) is begin + -- By default, if no size clause is present, an enumeration type with + -- Convention C is assumed to interface to a C enum, and has integer + -- size. This applies to types. For subtypes, verify that its base + -- type has no size clause either. + if Has_Foreign_Convention (Typ) and then not Has_Size_Clause (Typ) + and then not Has_Size_Clause (Base_Type (Typ)) and then Esize (Typ) < Standard_Integer_Size then Init_Esize (Typ, Standard_Integer_Size); + else + -- If the enumeration type interfaces to C, and it has a size clause + -- that specifies less than int size, it warrants a warning. The + -- user may intend the C type to be an enum or a char, so this is + -- not by itself an error that the Ada compiler can detect, but it + -- it is a worth a heads-up. For Boolean and Character types we + -- assume that the programmer has the proper C type in mind. + + if Convention (Typ) = Convention_C + and then Has_Size_Clause (Typ) + and then Esize (Typ) /= Esize (Standard_Integer) + and then not Is_Boolean_Type (Typ) + and then not Is_Character_Type (Typ) + then + Error_Msg_N + ("C enum types have the size of a C int?", Size_Clause (Typ)); + end if; + Adjust_Esize_For_Alignment (Typ); end if; end Freeze_Enumeration_Type;