[Ada] Eliminate false positives on "no entities ..." message

Arnaud Charlet charlet@adacore.com
Wed Jan 22 11:18:00 GMT 2014


This change avoids issuing the "no entities .." message for a with'ed
package if serious errors have been found. This eliminates some annoying
false positives, as shown by the following example, compiled with -gnatwa

     1. with System; use System;
     2. package WarnNoEnt is
     3.    X : Integer := "ABC";
                          |
        >>> expected type "Standard.Integer"
        >>> found a string type

     4.    Y : Integer := 0;
     5.     for Y'Address use X'Address;
     6. end WarnNoEnt;

Before this change, line 1 issued a "no entities" warning

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

2014-01-22  Robert Dewar  <dewar@adacore.com>

	* sem_warn.adb (Check_Use_Clause): Don't give no entities used
	msg if errors found.
	(Check_One_Unit): Same change.

-------------- next part --------------
Index: sem_warn.adb
===================================================================
--- sem_warn.adb	(revision 206918)
+++ sem_warn.adb	(working copy)
@@ -2130,11 +2130,18 @@
                   Nam := First (Names (N));
                   while Present (Nam) loop
                      if Entity (Nam) = Pack then
-                        Error_Msg_Qual_Level := 1;
-                        Error_Msg_NE -- CODEFIX
-                          ("?u?no entities of package& are referenced!",
-                             Nam, Pack);
-                        Error_Msg_Qual_Level := 0;
+
+                        --  Suppress message if any serious errors detected
+                        --  that turn off expansion, and thus result in false
+                        --  positives for this warning.
+
+                        if Serious_Errors_Detected = 0 then
+                           Error_Msg_Qual_Level := 1;
+                           Error_Msg_NE -- CODEFIX
+                             ("?u?no entities of package& are referenced!",
+                                Nam, Pack);
+                           Error_Msg_Qual_Level := 0;
+                        end if;
                      end if;
 
                      Next (Nam);
@@ -2402,8 +2409,13 @@
                            --  Else give the warning
 
                            else
-                              if not
-                                Has_Unreferenced (Entity (Name (Item)))
+                              --  Warn if we unreferenced flag set and we have
+                              --  not had serious errors. The reason we inhibit
+                              --  the message if there are errors is to prevent
+                              --  false positives from disabling expansion.
+
+                              if not Has_Unreferenced (Entity (Name (Item)))
+                                and then Serious_Errors_Detected = 0
                               then
                                  Error_Msg_N -- CODEFIX
                                    ("?u?no entities of & are referenced!",
@@ -2541,6 +2553,8 @@
    --  Start of processing for Check_Unused_Withs
 
    begin
+      --  Immediate return if no semantics or warning flag not set
+
       if not Opt.Check_Withs or else Operating_Mode = Check_Syntax then
          return;
       end if;


More information about the Gcc-patches mailing list