Style checks must apply to suprogram instantiations, even though they are
rewritten by means of a wrapper package and appear not to come from source.
Missing overriding indicators (for primitives of untagged types) and casing
anomalies in the text of the instance are now diagnosed.

the command
   gcc -c -gnat05 -gnatyO -gnatc instances.ads
must yield:

   instances.ads:13:04: in instantiation at generics.ads:4
   instances.ads:13:04: (style)
         missing "overriding" indicator in declaration of "Ms"
---
package Generics is
   generic
      type Pt is private;
   procedure Gen_Func (X : in out Pt);
end Generics;
---
package body Generics is

   procedure Gen_Func (X : in out PT) is
   begin
      null;
   end;
end;
---
with Generics;
use  Generics;

package Instances is

   type T is record
      A : Integer;
      B : Integer;
   end record;
   procedure Ms (X : in out T);

   type NT is new T;
   procedure Ms is new Gen_Func (PT => NT);
end Instances;
---

the command:
   gcc -c -gnatyr instance_style.adb
must yield:

   instance_style.adb:14:26: (style) bad casing of "G" declared at line 6
   instance_style.adb:14:29: (style) bad casing of "X" declared at line 2

---
procedure  Instance_Style is
   X : constant Integer := 15;

   generic
      Val : Integer;
   procedure G;

   procedure G is begin
      if Val /= 10 then
         null;
      end if;
   end G;

   procedure Inst is new g (x);
begin
   Inst;
end Instance_Style;

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

2012-04-02  Ed Schonberg  <schonb...@adacore.com>

        * sem_ch12.adb (Analyze_Subprogram_Instantiation): Do not suppress
        style checks, because the subprogram instance itself may contain
        violations of syle rules.
        * style.adb (Missing_Overriding): Check for missing overriding
        indicator on a subprogram instance.

Index: style.adb
===================================================================
--- style.adb   (revision 186067)
+++ style.adb   (working copy)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2012, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -236,7 +236,13 @@
 
    procedure Missing_Overriding (N : Node_Id; E : Entity_Id) is
    begin
-      if Style_Check_Missing_Overriding and then Comes_From_Source (N) then
+
+      --  Perform the check on source subprograms and on subprogram instances,
+      --  because these can be primitives of untagged types.
+
+      if Style_Check_Missing_Overriding
+        and then (Comes_From_Source (N) or else Is_Generic_Instance (E))
+      then
          if Nkind (N) = N_Subprogram_Body then
             Error_Msg_NE -- CODEFIX
               ("(style) missing OVERRIDING indicator in body of&", N, E);
Index: sem_ch12.adb
===================================================================
--- sem_ch12.adb        (revision 186067)
+++ sem_ch12.adb        (working copy)
@@ -4404,9 +4404,6 @@
       Parent_Installed : Boolean := False;
       Renaming_List    : List_Id;
 
-      Save_Style_Check : constant Boolean := Style_Check;
-      --  Save style check mode for restore on exit
-
       procedure Analyze_Instance_And_Renamings;
       --  The instance must be analyzed in a context that includes the mappings
       --  of generic parameters into actuals. We create a package declaration
@@ -4587,11 +4584,13 @@
 
       Instantiation_Node := N;
 
-      --  Turn off style checking in instances. If the check is enabled on the
-      --  generic unit, a warning in an instance would just be noise. If not
-      --  enabled on the generic, then a warning in an instance is just wrong.
+      --  For package instantiations we turn off style checks, because they
+      --  will have been emitted in the generic. For subprogram instantiations
+      --  we want to apply at least the check on overriding indicators so we
+      --  do not modify the style check status.
 
-      Style_Check := False;
+      --  The renaming declarations for the actuals do not come from source and
+      --  will not generate spurious warnings.
 
       Preanalyze_Actuals (N);
 
@@ -4859,8 +4858,6 @@
          Generic_Renamings_HTable.Reset;
       end if;
 
-      Style_Check := Save_Style_Check;
-
    <<Leave>>
       if Has_Aspects (N) then
          Analyze_Aspect_Specifications (N, Act_Decl_Id);
@@ -4875,8 +4872,6 @@
          if Env_Installed then
             Restore_Env;
          end if;
-
-         Style_Check := Save_Style_Check;
    end Analyze_Subprogram_Instantiation;
 
    -------------------------

Reply via email to