diff mbox series

[Ada] Spurious ineffective use_type_clause warning on private type

Message ID 20171014164803.GA103178@adacore.com
State New
Headers show
Series [Ada] Spurious ineffective use_type_clause warning on private type | expand

Commit Message

Pierre-Marie de Rodat Oct. 14, 2017, 4:48 p.m. UTC
This patch corrects an issue whereby a defaulted formal subprogram was not
being accounted for when checking for ineffective use_type_clauses on private
types used as generic actuals.

------------
-- Source --
------------

--  types.ads

package Types is
   type Enum_1 is private;
private
   type Enum_1 is (Red_1, Green_1, Blue_1);
end;

--  main.adb

with Types;
procedure Main is

   generic
      type Elem is private;
      with function "=" (L, R : Elem)
         return Boolean is <>;
   package Nested_4 is end;

   use type Types.Enum_1;
   package X is new Nested_4 (Types.Enum_1);
begin
   null;
end;

----------------------------
-- Compilation and output --
----------------------------

& gnatmake -q -gnatwu main.adb
main.adb:6:21: warning: function "=" is not referenced
main.adb:11:12: warning: package "X" is not referenced

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

2017-10-14  Justin Squirek  <squirek@adacore.com>

	* sem_ch8.adb (Analyze_Subprogram_Renaming): Modify condition that
	triggers marking on formal subprograms.
diff mbox series

Patch

Index: sem_ch8.adb
===================================================================
--- sem_ch8.adb	(revision 253753)
+++ sem_ch8.adb	(working copy)
@@ -3644,19 +3644,16 @@ 
       --  and mark any use_package_clauses that affect the visibility of the
       --  implicit generic actual.
 
-      if From_Default (N)
-        and then Is_Generic_Actual_Subprogram (New_S)
-        and then Present (Alias (New_S))
+      if Is_Generic_Actual_Subprogram (New_S)
+        and then (Is_Intrinsic_Subprogram (New_S) or else From_Default (N))
       then
-         Mark_Use_Clauses (Alias (New_S));
+         Mark_Use_Clauses (New_S);
 
-      --  Check intrinsic operators used as generic actuals since they may
-      --  make a use_type_clause effective.
+         --  Handle overloaded subprograms
 
-      elsif Is_Generic_Actual_Subprogram (New_S)
-        and then Is_Intrinsic_Subprogram (New_S)
-      then
-         Mark_Use_Clauses (New_S);
+         if Present (Alias (New_S)) then
+            Mark_Use_Clauses (Alias (New_S));
+         end if;
       end if;
    end Analyze_Subprogram_Renaming;