[multiple changes]
authorArnaud Charlet <charlet@gcc.gnu.org>
Thu, 20 Feb 2014 13:52:08 +0000 (14:52 +0100)
committerArnaud Charlet <charlet@gcc.gnu.org>
Thu, 20 Feb 2014 13:52:08 +0000 (14:52 +0100)
2014-02-20  Vincent Celier  <celier@adacore.com>

* errutil.adb (Initialize): Properly initialize entry in table
Warnings when warnings are suppressed.

2014-02-20  Robert Dewar  <dewar@adacore.com>

* s-os_lib.ads: Add warning about non-portability of Rename_File.
* sem_util.ads, sem_util.adb (Is_Junk_Name): New function.
* sem_warn.adb: Use Is_Junk_Name to suppress some warnings.
* gnat_ugn.texi: Document no warnings on junk variable names.
* layout.adb: Minor code reorganization (use Ekind_In).
* stringt.adb: Move initialization of Null_String_Id to Initialize
routine.

2014-02-20  Ed Schonberg  <schonberg@adacore.com>

* sem_ch13.adb: Initialize optional Element_Id.

From-SVN: r207947

gcc/ada/ChangeLog
gcc/ada/errutil.adb
gcc/ada/gnat_rm.texi
gcc/ada/gnat_ugn.texi
gcc/ada/layout.adb
gcc/ada/s-os_lib.ads
gcc/ada/sem_ch13.adb
gcc/ada/sem_util.adb
gcc/ada/sem_util.ads
gcc/ada/sem_warn.adb
gcc/ada/stringt.adb

index ccd4d0e..998272e 100644 (file)
@@ -1,3 +1,22 @@
+2014-02-20  Vincent Celier  <celier@adacore.com>
+
+       * errutil.adb (Initialize): Properly initialize entry in table
+       Warnings when warnings are suppressed.
+
+2014-02-20  Robert Dewar  <dewar@adacore.com>
+
+       * s-os_lib.ads: Add warning about non-portability of Rename_File.
+       * sem_util.ads, sem_util.adb (Is_Junk_Name): New function.
+       * sem_warn.adb: Use Is_Junk_Name to suppress some warnings.
+       * gnat_ugn.texi: Document no warnings on junk variable names.
+       * layout.adb: Minor code reorganization (use Ekind_In).
+       * stringt.adb: Move initialization of Null_String_Id to Initialize
+       routine.
+
+2014-02-20  Ed Schonberg  <schonberg@adacore.com>
+
+       * sem_ch13.adb: Initialize optional Element_Id.
+
 2014-02-20  Robert Dewar  <dewar@adacore.com>
 
        * s-os_lib.ads (Rename_File): Minor commment addition.
index 8053bb5..0d4af6c 100644 (file)
@@ -31,6 +31,7 @@ with Opt;      use Opt;
 with Output;   use Output;
 with Scans;    use Scans;
 with Sinput;   use Sinput;
+with Stringt;  use Stringt;
 with Stylesw;  use Stylesw;
 
 package body Errutil is
@@ -599,9 +600,11 @@ package body Errutil is
       Warnings.Init;
 
       if Warning_Mode = Suppress then
-         Warnings.Increment_Last;
-         Warnings.Table (Warnings.Last).Start := Source_Ptr'First;
-         Warnings.Table (Warnings.Last).Stop  := Source_Ptr'Last;
+         Warnings.Append
+           (New_Val =>
+              (Start  => Source_Ptr'First,
+               Stop   => Source_Ptr'Last,
+               Reason => Null_String_Id));
       end if;
    end Initialize;
 
index 4de4393..c02169f 100644 (file)
@@ -7133,6 +7133,13 @@ This is particularly useful for clearly signaling that a particular
 parameter is not modified, even though the spec suggests that it might
 be.
 
+For the variable case, warnings are never given for unreferenced variables
+whose name contains one of the substrings
+@code{DISCARD, DUMMY, IGNORE, JUNK, UNUSED} in any casing. Such names
+are typically to be used in cases where such warnings are expected.
+Thus it is never necessary to use @code{pragma Unmodified} for such
+variables, though it is harmless to do so.
+
 @node Pragma Unreferenced
 @unnumberedsec Pragma Unreferenced
 @findex Unreferenced
@@ -7183,6 +7190,13 @@ mentioned in @code{with} clauses (similar to the usage of pragma
 @code{Elaborate_All}. The effect is to suppress warnings about unreferenced
 units and unreferenced entities within these units.
 
+For the variable case, warnings are never given for unreferenced variables
+whose name contains one of the substrings
+@code{DISCARD, DUMMY, IGNORE, JUNK, UNUSED} in any casing. Such names
+are typically to be used in cases where such warnings are expected.
+Thus it is never necessary to use @code{pragma Unreferenced} for such
+variables, though it is harmless to do so.
+
 @node Pragma Unreferenced_Objects
 @unnumberedsec Pragma Unreferenced_Objects
 @findex Unreferenced_Objects
index b97ece0..b61254d 100644 (file)
@@ -4852,7 +4852,12 @@ Internal GNAT unit @code{with}'ed by application unit
 Values known to be out of range at compile time
 
 @item
-Unreferenced labels and variables
+Unreferenced or unmodified variables. Note that a special
+exemption applies to variables which contain any of the substrings
+@code{DISCARD, DUMMY, IGNORE, JUNK, UNUSED}, in any casing. Such variables
+are considered likely to be intentionally used in a situation where
+otherwise a warning would be given, so warnings of this kind are
+always suppressed for such variables.
 
 @item
 Address overlays that could clobber memory
index 75957c5..ada36de 100644 (file)
@@ -2276,9 +2276,7 @@ package body Layout is
       --  original, nothing else needs to be done in this case, since the
       --  components themselves are all shared.
 
-      if (Ekind (E) = E_Record_Subtype
-            or else
-          Ekind (E) = E_Class_Wide_Subtype)
+      if Ekind_In (E, E_Record_Subtype, E_Class_Wide_Subtype)
         and then Present (Cloned_Subtype (E))
       then
          Set_Esize     (E, Esize     (Cloned_Subtype (E)));
index 00aebc2..03557b6 100644 (file)
@@ -301,9 +301,14 @@ package System.OS_Lib is
       New_Name : String;
       Success  : out Boolean);
    --  Rename a file. Success is set True or False indicating if the rename is
-   --  successful or not. Note that on some Systems (notably Windows), if there
-   --  is already an existing file with the name New_Name, that is one of the
-   --  conditions that can cause failure.
+   --  successful or not.
+   --
+   --  WARNING: In one very important respect, this function is significantly
+   --  non-portable. If New_Name already exists then on Unix systems, the call
+   --  deletes the existing file, and the call signals success. On Windows, the
+   --  call fails, without doing the rename operation. See also the procedure
+   --  Ada.Directories.Rename, which portably provides the windows semantics,
+   --  i.e. fails if the output file already exists.
 
    --  The following defines the mode for the Copy_File procedure below. Note
    --  that "time stamps and other file attributes" in the descriptions below
index 1e81110..79ca903 100644 (file)
@@ -11493,6 +11493,7 @@ package body Sem_Ch13 is
       First_Id       := Empty;
       Next_Id        := Empty;
       Has_Element_Id := Empty;
+      Element_Id     := Empty;
 
       --  Each expression must resolve to a function with the proper signature
 
index ceedb7d..435db38 100644 (file)
@@ -10369,6 +10369,45 @@ package body Sem_Util is
       end if;
    end Is_Iterator;
 
+   ------------------
+   -- Is_Junk_Name --
+   ------------------
+
+   function Is_Junk_Name (N : Name_Id) return Boolean is
+      function Match (S : String) return Boolean;
+      --  Return true if substring S is found in Name_Buffer (1 .. Name_Len)
+
+      -----------
+      -- Match --
+      -----------
+
+      function Match (S : String) return Boolean is
+         Slen1 : constant Integer := S'Length - 1;
+
+      begin
+         for J in 1 .. Name_Len - S'Length + 1 loop
+            if Name_Buffer (J .. J + Slen1) = S then
+               return True;
+            end if;
+         end loop;
+
+         return False;
+      end Match;
+
+   --  Start of processing for Is_Junk_Name
+
+   begin
+      Get_Unqualified_Decoded_Name_String (N);
+      Set_All_Upper_Case;
+
+      return
+        Match ("DISCARD") or else
+        Match ("DUMMY")   or else
+        Match ("IGNORE")  or else
+        Match ("JUNK")    or else
+        Match ("UNUSED");
+   end Is_Junk_Name;
+
    ------------
    -- Is_LHS --
    ------------
index 3377c7c..94e4465 100644 (file)
@@ -1214,6 +1214,16 @@ package Sem_Util is
    --  AI05-0139-2: Check whether Typ is one of the predefined interfaces in
    --  Ada.Iterator_Interfaces, or it is derived from one.
 
+   function Is_Junk_Name (N : Name_Id) return Boolean;
+   --  Returns True if the given name contains any of the following substrings
+   --    discard
+   --    dummy
+   --    ignore
+   --    junk
+   --    unused
+   --  Used to suppress warnings on names matching these patterns. The contents
+   --  of Name_Buffer and Name_Len are desteoyed by this call.
+
    type Is_LHS_Result is (Yes, No, Unknown);
    function Is_LHS (N : Node_Id) return Is_LHS_Result;
    --  Returns Yes if N is definitely used as Name in an assignment statement.
index 6193a8f..e73a54e 100644 (file)
@@ -1265,6 +1265,7 @@ package body Sem_Warn is
                      if Referenced (E1) then
                         if not Has_Unmodified (E1)
                           and then not Warnings_Off_E1
+                          and then not Is_Junk_Name (Chars (E1))
                         then
                            Output_Reference_Error
                              ("?v?variable& is read but never assigned!");
@@ -1272,6 +1273,7 @@ package body Sem_Warn is
 
                      elsif not Has_Unreferenced (E1)
                        and then not Warnings_Off_E1
+                       and then not Is_Junk_Name (Chars (E1))
                      then
                         Output_Reference_Error -- CODEFIX
                           ("?v?variable& is never read and never assigned!");
@@ -3899,6 +3901,7 @@ package body Sem_Warn is
       if not Referenced_Check_Spec (E)
         and then not Has_Pragma_Unreferenced_Check_Spec (E)
         and then not Warnings_Off_Check_Spec (E)
+        and then not Is_Junk_Name (Chars (Spec_E))
       then
          case Ekind (E) is
             when E_Variable =>
@@ -4105,6 +4108,7 @@ package body Sem_Warn is
         and then not Is_Exported (Ent)
         and then Safe_To_Capture_Value (N, Ent)
         and then not Has_Pragma_Unreferenced_Check_Spec (Ent)
+        and then not Is_Junk_Name (Chars (Ent))
       then
          --  Before we issue the message, check covering exception handlers.
          --  Search up tree for enclosing statement sequences and handlers.
index e5d1573..5a0c89c 100644 (file)
@@ -121,6 +121,11 @@ package body Stringt is
    begin
       String_Chars.Init;
       Strings.Init;
+
+      --  Set up the null string
+
+      Start_String;
+      Null_String_Id := End_String;
    end Initialize;
 
    ----------
@@ -472,11 +477,4 @@ package body Stringt is
       end if;
    end Write_String_Table_Entry;
 
---  Setup the null string
-
-begin
-   Initialize;
-   Start_String;
-   Null_String_Id := End_String;
-
 end Stringt;