[Ada] Update output of verbose error summary
authorGhjuvan Lacambre <lacambre@adacore.com>
Thu, 23 Apr 2020 09:26:54 +0000 (11:26 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Thu, 18 Jun 2020 09:08:33 +0000 (05:08 -0400)
2020-06-18  Ghjuvan Lacambre  <lacambre@adacore.com>

gcc/ada/

* errout.adb (Write_Error_Summary): Display number of warnings
treated as errors.
* errutil.ads: Update comment.

gcc/ada/errout.adb
gcc/ada/errutil.ads

index 993dddf9112471ae42224db9a38cb6922bf462c5..8c60a3f93596816499ee9fa2abd3ceebfae36fa9 100644 (file)
@@ -1870,30 +1870,77 @@ package body Errout is
             Write_Str (" errors");
          end if;
 
-         if Warnings_Detected - Warning_Info_Messages /= 0 then
-            Write_Str (", ");
-            Write_Int (Warnings_Detected);
-            Write_Str (" warning");
+         --  We now need to output warnings. When using -gnatwe, all warnings
+         --  should be treated as errors, except for warnings originating from
+         --  the use of the Compile_Time_Warning pragma. Another situation
+         --  where a warning might be treated as an error is when the source
+         --  code contains a Warning_As_Error pragma.
+         --  When warnings are treated as errors, we still log them as
+         --  warnings, but we add a message denoting how many of these warnings
+         --  are also errors.
 
-            if Warnings_Detected - Warning_Info_Messages /= 1 then
-               Write_Char ('s');
-            end if;
+         declare
+            Warnings_Count : constant Int :=
+               Warnings_Detected - Warning_Info_Messages;
+
+            Compile_Time_Warnings : Int;
+            --  Number of warnings that come from a Compile_Time_Warning
+            --  pragma.
+
+            Non_Compile_Time_Warnings : Int;
+            --  Number of warnings that do not come from a Compile_Time_Warning
+            --  pragmas.
 
-            if Warning_Mode = Treat_As_Error then
-               Write_Str (" (treated as error");
+         begin
+            if Warnings_Count > 0 then
+               Write_Str (", ");
+               Write_Int (Warnings_Count);
+               Write_Str (" warning");
 
-               if Warnings_Detected /= 1 then
+               if Warnings_Count > 1 then
                   Write_Char ('s');
                end if;
 
-               Write_Char (')');
+               Compile_Time_Warnings := Count_Compile_Time_Pragma_Warnings;
+               Non_Compile_Time_Warnings :=
+                  Warnings_Count - Compile_Time_Warnings;
+
+               if Warning_Mode = Treat_As_Error
+                 and then Non_Compile_Time_Warnings > 0
+               then
+                  Write_Str (" (");
+
+                  if Compile_Time_Warnings > 0 then
+                     Write_Int (Non_Compile_Time_Warnings);
+                     Write_Str (" ");
+                  end if;
+
+                  Write_Str ("treated as error");
 
-            elsif Warnings_Treated_As_Errors /= 0 then
-               Write_Str (" (");
-               Write_Int (Warnings_Treated_As_Errors);
-               Write_Str (" treated as errors)");
+                  if Non_Compile_Time_Warnings > 1 then
+                     Write_Char ('s');
+                  end if;
+
+                  Write_Char (')');
+
+               elsif Warnings_Treated_As_Errors > 0 then
+                  Write_Str (" (");
+
+                  if Warnings_Treated_As_Errors /= Warnings_Count then
+                     Write_Int (Warnings_Treated_As_Errors);
+                     Write_Str (" ");
+                  end if;
+
+                  Write_Str ("treated as error");
+
+                  if Warnings_Treated_As_Errors > 1 then
+                     Write_Str ("s");
+                  end if;
+
+                  Write_Str (")");
+               end if;
             end if;
-         end if;
+         end;
 
          if Warning_Info_Messages + Report_Info_Messages /= 0 then
             Write_Str (", ");
index 705acbcaf7245d94e907685c4b653a0345ad8ff1..56bd242eaff04f74e3feb4002cbe5aa974f922b3 100644 (file)
@@ -30,8 +30,7 @@
 --  Err_Vars. Like Errout, it also uses the common variables and routines
 --  in package Erroutc.
 
---  This package is used by the preprocessor (gprep.adb) and the project
---  manager (prj-err.ads).
+--  This package is used by the preprocessor (gprep.adb).
 
 with Styleg;
 with Types; use Types;