From 943c82d7b9bc15161ac344953b2deb0a4121b279 Mon Sep 17 00:00:00 2001 From: Justin Squirek Date: Tue, 13 Aug 2019 08:06:50 +0000 Subject: [PATCH] [Ada] Disable anonymous allocator warning for library-level objects This patch modifies the behavior of anonymous allocator warnings so that they no longer get triggered in the case of an object declaration at library-level. 2019-08-13 Justin Squirek gcc/ada/ * exp_ch4.adb (Expand_N_Allocator): Add condition to detect library-level object declarations gcc/testsuite/ * gnat.dg/anon3.adb, gnat.dg/anon3.ads: New testcase. From-SVN: r274338 --- gcc/ada/ChangeLog | 5 +++++ gcc/ada/exp_ch4.adb | 5 ++++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gnat.dg/anon3.adb | 6 ++++++ gcc/testsuite/gnat.dg/anon3.ads | 4 ++++ 5 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gnat.dg/anon3.adb create mode 100644 gcc/testsuite/gnat.dg/anon3.ads diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index f4ad36d2dbe..5a9a9cced88 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2019-08-13 Justin Squirek + + * exp_ch4.adb (Expand_N_Allocator): Add condition to detect + library-level object declarations + 2019-08-13 Eric Botcazou * doc/gnat_ugn/building_executable_programs_with_gnat.rst diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index 6f2fe325507..4404c5dca9d 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 206d39d1c72..8ec5ec02440 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-08-13 Justin Squirek + + * gnat.dg/anon3.adb, gnat.dg/anon3.ads: New testcase. + 2019-08-13 Eric Botcazou * gnat.dg/generic_inst8.adb, gnat.dg/generic_inst8.ads, diff --git a/gcc/testsuite/gnat.dg/anon3.adb b/gcc/testsuite/gnat.dg/anon3.adb new file mode 100644 index 00000000000..86286335981 --- /dev/null +++ b/gcc/testsuite/gnat.dg/anon3.adb @@ -0,0 +1,6 @@ +-- { dg-do compile } +-- { dg-options "-gnatwa" } + +package body Anon3 is + procedure Dummy is null; +end Anon3; diff --git a/gcc/testsuite/gnat.dg/anon3.ads b/gcc/testsuite/gnat.dg/anon3.ads new file mode 100644 index 00000000000..39978c20188 --- /dev/null +++ b/gcc/testsuite/gnat.dg/anon3.ads @@ -0,0 +1,4 @@ +package Anon3 is + X : access Integer := new Integer; + procedure Dummy; +end Anon3; -- 2.30.2