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]

[Ada] Implement pragma Ordered and -gnatw.u


The warning flag -gnatw.u replaces the style switch -gnatyE to cause
warnings on comparisons and subranges of unordered enumeration types.
If the switch -gnatw.u is not given, then no enumeration types are
considered unordered, and no warnings are issued. If this warning
switch is present, then any enumeration types not marked by pragma
Ordered (a new pragma included in this patch), are considered to
be unordered, and comparisons and ranges will be flagged as shown
in the following test:

     1. package OrderedP is
     2.    type E1 is (Red, Blue, Green);
     3.    type E2 is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
     4.    pragma Ordered (E2);
     5. end OrderedP;

     1. with OrderedP; use OrderedP;
     2. package Ordered is
     3.    B1 : Boolean := Red in Green .. Blue;
                                        |
        >>> warning: subrange of unordered enumeration type

     4.    B2 : Boolean := Tue in Mon .. Fri;
     5.    B3 : Boolean := Red > Green;
                               |
        >>> warning: comparison on unordered enumeration type

     6.    B4 : Boolean := Tue > Wed;
     7. end;

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

2010-09-09  Robert Dewar  <dewar@adacore.com>

	* cstand.adb: Mark Boolean and Character types as Ordered
	* einfo.adb (Has_Pragma_Ordered): New flag
	* einfo.ads (Has_Pragma_Ordered): New flag
	* g-calend.ads: Mark Day_Name as Ordered
	* opt.ads: Mark Ada_Version_Type as Ordered
	(Warn_On_Unordered_Enumeration_Type): New flag
	* par-prag.adb: Add procdessing for pragma Ordered
	* s-ficobl.ads (Read_File_Mode): New subtype
	* s-fileio.adb: Use Read_File_Mode instead of explicit ranges
	* s-taskin.ads: Mark Entry_Call_State as ordered
	* sem_ch3.adb (Build_Derived_Enumeration_Type): Inherit
	Has_Pragma_Ordered.
	* sem_ch6.ads: Mark Conformance_Type as Ordered
	* sem_prag.adb: Implement pragma Ordered
	* sem_res.adb (Bad_Unordered_Enumeration_Reference): New function
	(Resolve_Comparison_Op): Diagnose unordered comparison
	(Resolve_Range): Diagnose unordered range
	* sem_warn.adb (Warn_On_Unordered_Enumeration_Type): New flag (from
	-gnatw.u/U)
	* snames.ads-tmpl: Add entry for pragma Ordered
	* style.ads (Check_Enumeration_Subrange): Removed
	* styleg.adb (Check_Enumeration_Subrange): Removed
	* styleg.ads (Check_Enumeration_Subrange): Removed
	* stylesw.adb: Remove handling of -gnatyE switch
	* stylesw.ads: (Style_Check_Enumeration_Subranges): Removed
	* vms_data.ads: Remove -gnatyE entries
	Add -gnatw.u entries
	* ug_words: Entries for -gnatw.u and -gnatw.U
	* gnat_ugn.texi: Document -gnatw.u/-gnatw.U switches
	* gnat_rm.texi: Document pragma Ordered.
	* s-tasren.adb: Avoid unnecessary comparison on unordered enumeration.
	* s-tpobop.adb: Remove comparison on unordered enumeration type.

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]