In some cases involving a package spec using object.method notation
in e.g. subprogram aspects, an old change in Complete_Object_Operation
would disable the proper detection of an unused "with" clause.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* sem_ch4.adb (Complete_Object_Operation): Only mark entities
referenced if we are compiling the extended main unit.
* sem_attr.adb (Analyze_Attribute [Attribute_Tag]): Record a
reference on the type and its scope.
diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -6288,6 +6288,15 @@ package body Sem_Attr is
if Comes_From_Source (N) then
Check_Not_Incomplete_Type;
+
+ -- 'Tag requires visibility on the corresponding package holding
+ -- the tag, so record a reference here, to avoid spurious unused
+ -- with_clause reported when compiling the main unit.
+
+ if In_Extended_Main_Source_Unit (Current_Scope) then
+ Set_Referenced (P_Type, True);
+ Set_Referenced (Scope (P_Type), True);
+ end if;
end if;
-- Set appropriate type
diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -9010,16 +9010,20 @@ package body Sem_Ch4 is
Rewrite (First_Actual, Obj);
end if;
- -- The operation is obtained from the dispatch table and not by
- -- visibility, and may be declared in a unit that is not explicitly
- -- referenced in the source, but is nevertheless required in the
- -- context of the current unit. Indicate that operation and its scope
- -- are referenced, to prevent spurious and misleading warnings. If
- -- the operation is overloaded, all primitives are in the same scope
- -- and we can use any of them.
-
- Set_Referenced (Entity (Subprog), True);
- Set_Referenced (Scope (Entity (Subprog)), True);
+ if In_Extended_Main_Source_Unit (Current_Scope) then
+ -- The operation is obtained from the dispatch table and not by
+ -- visibility, and may be declared in a unit that is not
+ -- explicitly referenced in the source, but is nevertheless
+ -- required in the context of the current unit. Indicate that
+ -- operation and its scope are referenced, to prevent spurious and
+ -- misleading warnings. If the operation is overloaded, all
+ -- primitives are in the same scope and we can use any of them.
+ -- Don't do that outside the main unit since otherwise this will
+ -- e.g. prevent the detection of some unused with clauses.
+
+ Set_Referenced (Entity (Subprog), True);
+ Set_Referenced (Scope (Entity (Subprog)), True);
+ end if;
Rewrite (Node_To_Replace, Call_Node);