@@ -4421,10 +4421,13 @@ package body Exp_Ch4 is
begin
-- Warn on the presence of an allocator of an anonymous access type when
- -- enabled.
+ -- enabled except when its an object declaration at library level.
if Warn_On_Anonymous_Allocators
and then Ekind (PtrT) = E_Anonymous_Access_Type
+ and then not (Is_Library_Level_Entity (PtrT)
+ and then Nkind (Associated_Node_For_Itype (PtrT)) =
+ N_Object_Declaration)
then
Error_Msg_N ("?use of an anonymous access type allocator", N);
end if;
new file mode 100644
@@ -0,0 +1,6 @@
+-- { dg-do compile }
+-- { dg-options "-gnatwa" }
+
+package body Anon3 is
+ procedure Dummy is null;
+end Anon3;
new file mode 100644
@@ -0,0 +1,4 @@
+package Anon3 is
+ X : access Integer := new Integer;
+ procedure Dummy;
+end Anon3;