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-1642] [Ada] Spurious use_type clause warning
Date: Tue, 12 Jul 2022 12:27:03 +0000 (GMT)	[thread overview]
Message-ID: <20220712122703.85EBB3836F92@sourceware.org> (raw)

https://gcc.gnu.org/g:729d2e2a80768b6df008ea98979dbe34b7e4ab9a

commit r13-1642-g729d2e2a80768b6df008ea98979dbe34b7e4ab9a
Author: Justin Squirek <squirek@adacore.com>
Date:   Wed Jun 15 01:53:49 2022 +0000

    [Ada] Spurious use_type clause warning
    
    This patch corrects an error in the compiler whereby a spurious
    redundant use_type_clause warning gets issued when the clause appears in
    the context_clause of a package preceding a with_clause for a package
    with an identical use_clause in its specification.
    
    gcc/ada/
    
            * einfo.ads: Modify documentation for In_Use flag to include
            scope stack manipulation.
            * sem_ch8.adb (Use_One_Type): Add condition to return when
            attempting to detect redundant use_type_clauses in child units
            in certain cases.

Diff:
---
 gcc/ada/einfo.ads   |  4 ++++
 gcc/ada/sem_ch8.adb | 17 ++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads
index c5843f2903f..ed630191957 100644
--- a/gcc/ada/einfo.ads
+++ b/gcc/ada/einfo.ads
@@ -2309,6 +2309,10 @@ package Einfo is
 --       the corresponding entity. Reset at end of corresponding declarative
 --       part. The flag on a type is also used to determine the visibility of
 --       the primitive operators of the type.
+--
+--       Note that manipulation of scopes on the scope stack will also cause
+--       the flag to be set/unset since the setting of scopes affects
+--       visibility.
 
 --    Is_Abstract_Subprogram
 --       Defined in all subprograms and entries. Set for abstract subprograms.
diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
index cda787063eb..eb9e359e497 100644
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -10758,15 +10758,26 @@ package body Sem_Ch8 is
                      return;
                   end if;
 
-                  --  There is a redundant use_type_clause in a child unit.
-                  --  Determine which of the units is more deeply nested. If a
+                  --  If there is a redundant use_type_clause in a child unit
+                  --  determine which of the units is more deeply nested. If a
                   --  unit is a package instance, retrieve the entity and its
                   --  scope from the instance spec.
 
                   Ent1 := Entity_Of_Unit (Unit1);
                   Ent2 := Entity_Of_Unit (Unit2);
 
-                  if Scope (Ent2) = Standard_Standard then
+                  --  When the scope of both units' entities are
+                  --  Standard_Standard then neither Unit1 or Unit2 are child
+                  --  units - so return in that case.
+
+                  if Scope (Ent1) = Standard_Standard
+                    and then Scope (Ent2) = Standard_Standard
+                  then
+                     return;
+
+                  --  Otherwise, determine if one of the units is not a child
+
+                  elsif Scope (Ent2) = Standard_Standard then
                      Error_Msg_Sloc := Sloc (Clause2);
                      Err_No := Clause1;


                 reply	other threads:[~2022-07-12 12:27 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=20220712122703.85EBB3836F92@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: link
Be 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).