Commit 7029d96f by Ed Schonberg Committed by Pierre-Marie de Rodat

[Ada] More permissive use of GNAT attribute Enum_Rep

This patch allows the prefix of the attribute Enum_Rep to be an
attribute referece (such as Enum_Type'First). A recent patch had
restricted the prefix to be an object of a discrete type, which is
incompatible with orevious usage.

2019-07-01  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* sem_attr.adb (Analyze_Attribute, case Enum_Rep): Allow prefix
	of attribute to be an attribute reference of a discrete type.

gcc/testsuite/

	* gnat.dg/enum_rep.adb, gnat.dg/enum_rep.ads: New testcase.

From-SVN: r272881
parent 8b9aa1a9
2019-07-01 Ed Schonberg <schonberg@adacore.com>
* sem_attr.adb (Analyze_Attribute, case Enum_Rep): Allow prefix
of attribute to be an attribute reference of a discrete type.
2019-07-01 Eric Botcazou <ebotcazou@adacore.com> 2019-07-01 Eric Botcazou <ebotcazou@adacore.com>
* sem_ch12.adb (Analyze_Subprogram_Instantiation): Move up * sem_ch12.adb (Analyze_Subprogram_Instantiation): Move up
......
...@@ -3833,14 +3833,16 @@ package body Sem_Attr is ...@@ -3833,14 +3833,16 @@ package body Sem_Attr is
Check_Discrete_Type; Check_Discrete_Type;
Resolve (E1, P_Base_Type); Resolve (E1, P_Base_Type);
-- X'Enum_Rep case. X must be an object or enumeration literal, and -- X'Enum_Rep case. X must be an object or enumeration literal
-- it must be of a discrete type. -- (including an attribute reference), and it must be of a
-- discrete type.
elsif not elsif not
((Is_Object_Reference (P) ((Is_Object_Reference (P)
or else or else
(Is_Entity_Name (P) (Is_Entity_Name (P)
and then Ekind (Entity (P)) = E_Enumeration_Literal)) and then Ekind (Entity (P)) = E_Enumeration_Literal)
or else Nkind (P) = N_Attribute_Reference)
and then Is_Discrete_Type (Etype (P))) and then Is_Discrete_Type (Etype (P)))
then then
Error_Attr_P ("prefix of % attribute must be discrete object"); Error_Attr_P ("prefix of % attribute must be discrete object");
......
2019-07-01 Ed Schonberg <schonberg@adacore.com> 2019-07-01 Ed Schonberg <schonberg@adacore.com>
* gnat.dg/enum_rep.adb, gnat.dg/enum_rep.ads: New testcase.
2019-07-01 Ed Schonberg <schonberg@adacore.com>
* gnat.dg/derived_type6.adb, gnat.dg/derived_type6.ads: New * gnat.dg/derived_type6.adb, gnat.dg/derived_type6.ads: New
testcase. testcase.
......
-- { dg-do compile }
package body Enum_Rep is
procedure Foo is null;
end;
with Interfaces;
package Enum_Rep is
type My_Type is range 00 .. 100;
subtype My_Subtype2 is Interfaces.Unsigned_32
range My_Type'First'Enum_Rep .. My_Type'Last'Enum_Rep;
My_Type_First : constant My_Type := My_Type'First;
My_Type_Last : constant My_Type := My_Type'Last;
subtype My_Subtype is Interfaces.Unsigned_32
range My_Type_First'Enum_Rep .. My_Type_Last'Enum_Rep;
subtype My_Subtype1 is Interfaces.Unsigned_32
range My_Type'Enum_Rep (My_Type'First) ..
My_Type'Enum_Rep (MY_Type'Last);
procedure Foo;
end;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment