[Ada] Missing error on T'Enum_Rep with no parameter
Arnaud Charlet
charlet@adacore.com
Tue May 2 09:06:00 GMT 2017
This patch fixes a bug in which the compiler fails to give an error on
T'Enum_Rep, where T is a type. If X is an object of enumeration type T,
then X'Enum_Rep and T'Enum_Rep(X) are allowed, but not T'Enum_Rep.
The following test must get an error.
enum_val_test.adb:4:21: prefix of "Enum_Rep" attribute must be discrete object
procedure Enum_Val_Test is
type Color is (Red, Orange, Yellow);
Current_Index : Color := Orange;
Rep : Integer := Color'Enum_Rep; -- Illegal!
begin
null;
end Enum_Val_Test;
Tested on x86_64-pc-linux-gnu, committed on trunk
2017-05-02 Bob Duff <duff@adacore.com>
* sem_attr.adb (Attribute_Enum_Rep): Disallow T'Enum_Rep.
-------------- next part --------------
Index: sem_attr.adb
===================================================================
--- sem_attr.adb (revision 247479)
+++ sem_attr.adb (working copy)
@@ -3763,13 +3763,23 @@
--------------
when Attribute_Enum_Rep =>
+ -- T'Enum_Rep (X) case
+
if Present (E1) then
Check_E1;
Check_Discrete_Type;
Resolve (E1, P_Base_Type);
- elsif not Is_Discrete_Type (Etype (P)) then
- Error_Attr_P ("prefix of % attribute must be of discrete type");
+ -- X'Enum_Rep case. X must be an object or enumeration literal, and
+ -- it must be of a discrete type.
+
+ elsif not ((Is_Object_Reference (P)
+ or else (Is_Entity_Name (P)
+ and then Ekind (Entity (P)) =
+ E_Enumeration_Literal))
+ and then Is_Discrete_Type (Etype (P)))
+ then
+ Error_Attr_P ("prefix of % attribute must be discrete object");
end if;
Set_Etype (N, Universal_Integer);
More information about the Gcc-patches
mailing list