From a8d17a88a52d2f773423adb55399d23ed5ea03c8 Mon Sep 17 00:00:00 2001 From: Piotr Trojanek Date: Tue, 21 Jun 2022 10:17:57 +0200 Subject: [Ada] Warn on unset objects in packages with no bodies Fix an inconsistency, where GNAT was warning about references to unset objects inside generic packages with no bodies but not inside ordinary packages with no bodies. gcc/ada/ * sem_ch7.adb (Analyze_Package_Declaration): Check references to unset objects. gcc/testsuite/ * gnat.dg/specs/discr5.ads: Expect new warnings. * gnat.dg/specs/empty_variants.ads: Likewise. * gnat.dg/specs/pack13.ads: Likewise. --- gcc/ada/sem_ch7.adb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'gcc/ada') diff --git a/gcc/ada/sem_ch7.adb b/gcc/ada/sem_ch7.adb index 31c04ad..5c347bd 100644 --- a/gcc/ada/sem_ch7.adb +++ b/gcc/ada/sem_ch7.adb @@ -1253,6 +1253,13 @@ package body Sem_Ch7 is (Context => N, Is_Main_Unit => Parent (N) = Cunit (Main_Unit)); end if; + + -- Warn about references to unset objects, which is straightforward + -- for packages with no bodies. For packages with bodies this is more + -- complicated, because some of the objects might be set between spec + -- and body elaboration, in nested or child packages, etc. + + Check_References (Id); end if; -- Set Body_Required indication on the compilation unit node -- cgit v1.1