This patch prevents spurious ineffective use_clause warnings in certain cases
due to the possible rewritting of nodes within boolean expressions.

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

2017-11-16  Justin Squirek  <squi...@adacore.com>

        * sem.adb (Analyze): Remove requirement that the original node of N be
        an operator in the case that analysis on the node yields the relevant
        operator - so prefer it instead.

Index: sem.adb
===================================================================
--- sem.adb     (revision 254797)
+++ sem.adb     (working copy)
@@ -740,18 +740,33 @@
 
       Debug_A_Exit ("analyzing  ", N, "  (done)");
 
-      --  Mark relevant use-type and use-package clauses as effective using the
-      --  original node, because constant folding may have occurred and removed
-      --  references that need to be examined. If the node in question is
-      --  overloaded then this is deferred until resolution.
+      --  Mark relevant use-type and use-package clauses as effective
+      --  preferring the original node over the analyzed one in the case that
+      --  constant folding has occurred and removed references that need to be
+      --  examined. Also, if the node in question is overloaded then this is
+      --  deferred until resolution.
 
-      if Nkind (Original_Node (N)) in N_Op
-        and then Present (Entity (Original_Node (N)))
-        and then not Is_Overloaded (Original_Node (N))
-      then
-         Mark_Use_Clauses (Original_Node (N));
-      end if;
+      declare
+         Operat : Node_Id := Empty;
+      begin
+         --  Attempt to obtain a checkable operator node
 
+         if Nkind (Original_Node (N)) in N_Op then
+            Operat := Original_Node (N);
+         elsif Nkind (N) in N_Op then
+            Operat := N;
+         end if;
+
+         --  Mark the operator
+
+         if Present (Operat)
+           and then Present (Entity (Operat))
+           and then not Is_Overloaded (Operat)
+         then
+            Mark_Use_Clauses (Operat);
+         end if;
+      end;
+
       --  Now that we have analyzed the node, we call the expander to perform
       --  possible expansion. We skip this for subexpressions, because we don't
       --  have the type yet, and the expander will need to know the type before

Reply via email to