diff mbox series

[Ada] Spurious ineffective use_clause warning

Message ID 20190918083945.GA145238@adacore.com
State New
Headers show
Series [Ada] Spurious ineffective use_clause warning | expand

Commit Message

Pierre-Marie de Rodat Sept. 18, 2019, 8:39 a.m. UTC
This patch fixes an issue whereby expansion of post conditions may lead
to spurious ineffective use_clause warnings when a use type clause is
present in a package specification and a use package clause exists in
the package body on the package containing said type.

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

2019-09-18  Justin Squirek  <squirek@adacore.com>

gcc/ada/

	* sem_ch8.adb (Use_One_Type): Add guard to prevent warning on a
	reundant use package clause where there is no previous
	use_clause in the chain.

gcc/testsuite/

	* gnat.dg/warn30.adb, gnat.dg/warn30.ads: New testcase.
diff mbox series

Patch

--- gcc/ada/sem_ch8.adb
+++ gcc/ada/sem_ch8.adb
@@ -10337,11 +10337,18 @@  package body Sem_Ch8 is
          --  The package where T is declared is already used
 
          elsif In_Use (Scope (T)) then
-            Error_Msg_Sloc :=
-              Sloc (Find_Most_Prev (Current_Use_Clause (Scope (T))));
-            Error_Msg_NE -- CODEFIX
-              ("& is already use-visible through package use clause #??",
-               Id, T);
+            --  Due to expansion of contracts we could be attempting to issue
+            --  a spurious warning - so verify there is a previous use clause.
+
+            if Current_Use_Clause (Scope (T)) /=
+                 Find_Most_Prev (Current_Use_Clause (Scope (T)))
+            then
+               Error_Msg_Sloc :=
+                 Sloc (Find_Most_Prev (Current_Use_Clause (Scope (T))));
+               Error_Msg_NE -- CODEFIX
+                 ("& is already use-visible through package use clause #??",
+                  Id, T);
+            end if;
 
          --  The current scope is the package where T is declared
 

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/warn30.adb
@@ -0,0 +1,10 @@ 
+--  { dg-do compile }
+--  { dg-options "-gnatwa" }
+with Interfaces; use Interfaces;
+
+package body Warn30 is
+   procedure Incr (X : in out Interfaces.Integer_64) is
+   begin
+      X := X + 1;
+   end Incr;
+end Warn30;
\ No newline at end of file

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/warn30.ads
@@ -0,0 +1,6 @@ 
+with Interfaces; use type Interfaces.Integer_64;
+
+package Warn30 is
+   procedure Incr (X : in out Interfaces.Integer_64) with
+     Post => X = X'Old + 1;
+end Warn30;