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] New style check for overriding indicators.


A new style check has been introduced. When it is enabled, the compiler flags
the declarations or bodies of overriding operations, to enforce the rule that
the constructs should carry an explicit overriding indicator.

Compiling package Pack as follows:

   gcc -c -gnat05 -gnatyO pack.adb

must yield the following:

pack.adb:6:14: (style)
                   missing "overriding" indicator in body of "Set_Up"
pack.adb:12:13: (style)
                   missing "overriding" indicator in body of "+"
pack.ads:8:14: (style)
                   missing "overriding" indicator in declaration of "Set_Up"
pack.ads:9:14: (style)
                   missing "overriding" indicator in declaration of "Initiate"
pack.ads:11:14: (style)
                   missing "overriding" indicator in declaration of "Try"
pack.ads:14:13: (style)
                   missing "overriding" indicator in declaration of "+"

---
package Pack is
   type T1 is tagged null record;
   procedure Set_Up (Obj : in out T1);
   procedure Try (Obj : T1);
   procedure Initiate (Obj : T1);

   type T2 is new T1 with null record;
   procedure Set_Up (Obj : in out T2);        --  ERROR
   procedure Initiate (Obj : T2);             --  ERROR
   procedure Attempt (Obj : T2);
   procedure Try (Obj : T2) renames Attempt;  --  ERROR

   type Int is range -100 .. 100;
   function "+" (X, Y : Int) return Int;
end; --   Pack;
---
package body Pack is
   procedure Set_Up (Obj : in out T1) is begin null; end Set_Up;
   procedure Initiate (Obj : T1) is begin null; end Initiate;
   procedure Try (Obj : T1) is begin null; end Try;

   procedure Set_Up (Obj : in out T2) is begin null; end Set_Up;  -- ERROR

   overriding
     procedure Initiate (Obj : T2) is begin null; end Initiate;   -- OK
   procedure Attempt (Obj : T2) is begin null; end Attempt;       -- OK

   function "+" (X, Y : Int) return Int is
   begin
      return X;
   end;
end Pack;

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

2008-08-20  Ed Schonberg  <schonberg@adacore.com>

	* styleg-c.ads, styleg-c.adb (Missing_Overriding): new procedure to
	implement style check that overriding operations are explicitly marked
	at such.

	* style.ads (Missing_Overriding): new procedure that provides interface
	to previous one.

	* stylesw.ads, stylesw.adb: New style switch -gnatyO, to enable check
	that the declaration or body of overriding operations carries an
	explicit overriding indicator.

	* sem_ch8.adb
	(Analyze_Subprogram_Renaming): if operation is overriding, check whether
	explicit indicator should be present.

	* sem_ch6.adb (Verify_Overriding_Indicator,
	Check_Overriding_Indicator): If operation is overriding, check whether
	declaration and/or body of subprogram should be present

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]