public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-1626] [Ada] Warn on unset objects in packages with no bodies Date: Tue, 12 Jul 2022 12:25:41 +0000 (GMT) [thread overview] Message-ID: <20220712122541.AB4663851174@sourceware.org> (raw) https://gcc.gnu.org/g:a8d17a88a52d2f773423adb55399d23ed5ea03c8 commit r13-1626-ga8d17a88a52d2f773423adb55399d23ed5ea03c8 Author: Piotr Trojanek <trojanek@adacore.com> Date: Tue Jun 21 10:17:57 2022 +0200 [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. Diff: --- gcc/ada/sem_ch7.adb | 7 +++++++ gcc/testsuite/gnat.dg/specs/discr5.ads | 5 +++-- gcc/testsuite/gnat.dg/specs/empty_variants.ads | 4 ++-- gcc/testsuite/gnat.dg/specs/pack13.ads | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/gcc/ada/sem_ch7.adb b/gcc/ada/sem_ch7.adb index 31c04ad077d..5c347bd8b4f 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 diff --git a/gcc/testsuite/gnat.dg/specs/discr5.ads b/gcc/testsuite/gnat.dg/specs/discr5.ads index c265723ec47..79c234a487b 100644 --- a/gcc/testsuite/gnat.dg/specs/discr5.ads +++ b/gcc/testsuite/gnat.dg/specs/discr5.ads @@ -22,7 +22,7 @@ package Discr5 is subtype Rt is R(True); subtype Rf is R(False); - type R1 (D1 : Boolean) is new R (X) with record + type R1 (D1 : Boolean) is new R (X) with record -- { dg-warning "\"X\" may be referenced before it has a value" } FF : Float; case D1 is when True => @@ -38,7 +38,7 @@ package Discr5 is subtype R1t is R1 (True); subtype R1f is R1 (False); - type R2 (D2 : Boolean) is new R1 (Y) with record + type R2 (D2 : Boolean) is new R1 (Y) with record -- { dg-warning "\"Y\" may be referenced before it has a value" } FFF: System.Address; case D2 is when True => @@ -55,3 +55,4 @@ package Discr5 is subtype R2f is R2 (False); end Discr5; + diff --git a/gcc/testsuite/gnat.dg/specs/empty_variants.ads b/gcc/testsuite/gnat.dg/specs/empty_variants.ads index 079b64ac812..9b0cdadeae8 100644 --- a/gcc/testsuite/gnat.dg/specs/empty_variants.ads +++ b/gcc/testsuite/gnat.dg/specs/empty_variants.ads @@ -1,5 +1,4 @@ -- { dg-do compile } --- { dg-options "-gnatdF" } package Empty_Variants is @@ -23,10 +22,11 @@ package Empty_Variants is R : Rec; - I : Integer := R.I; + I : Integer := R.I; -- { dg-warning "\"R\.I\" may be referenced before it has a value" } J : Integer := R.J; K : Integer := R.K; L : Integer := R.L; M : Integer := R.L; end Empty_Variants; + diff --git a/gcc/testsuite/gnat.dg/specs/pack13.ads b/gcc/testsuite/gnat.dg/specs/pack13.ads index 4594ab7ca03..86145500ca0 100644 --- a/gcc/testsuite/gnat.dg/specs/pack13.ads +++ b/gcc/testsuite/gnat.dg/specs/pack13.ads @@ -20,6 +20,6 @@ package Pack13 is A : Arr; - package My_G is new G (Boolean, A(True).B); + package My_G is new G (Boolean, A(True).B); -- { dg-warning "\"A\" may be referenced before it has a value" } end Pack13;
reply other threads:[~2022-07-12 12:25 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220712122541.AB4663851174@sourceware.org \ --to=pmderodat@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).