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] Warning on (others => <>) that does not cover any components.


This patch adds a warning on a record aggregate that includes an association
with a box, when all other components of the record have explicit associations
in the aggregate.

Compiling:

  gcc -c -gnatwr question.ads

must yield:

   question.ads:13:53: warning: others choice is redundant
   question.ads:13:53: warning: previous choices cover all components
   question.ads:14:57: warning: others choice is redundant
   question.ads:14:57: warning: previous choices cover all components
   question.ads:14:72: warning: others choice is redundant
   question.ads:14:72: warning: previous choices cover all components
   question.ads:19:12: warning: "others" choice is redundant
   question.ads:19:12: warning: previous choices cover all values

---
package Question is

    type Mon_Enum_T is (A, B);

    type Mon_Record_T is record
        Mon_Enum : Mon_Enum_T;
    end record;

    type nested is record
       this : Mon_Record_T;
    end record;

    Mon_Record : Mon_Record_T := (Mon_Enum=>A,others=><>);
    My_Nest : Nested := (THis => (Mon_Enum => A, others => <>), others => <>);

    function Ma_Fonction(Mon_Enum : in Mon_Enum_T) return Boolean is
    ((case Mon_Enum is
      when A | B      => True,
      when others => False)); --line 14

end Question;

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

2016-04-18  Ed Schonberg  <schonberg@adacore.com>

	* sem_aggr.adb (Resolve_Record_Aggregate): If
	Warn_On_Redundant_Constructs is enabled, report a redundant box
	association that does not cover any components, as it done for
	redundant others associations in case statements.

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]