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-548] [Ada] Subprogram renaming fails to hide homograph Date: Tue, 17 May 2022 08:29:45 +0000 (GMT) [thread overview] Message-ID: <20220517082945.6E0983857407@sourceware.org> (raw) https://gcc.gnu.org/g:de0665fc7f195e12ede10abb6a98b10011e70807 commit r13-548-gde0665fc7f195e12ede10abb6a98b10011e70807 Author: Gary Dismukes <dismukes@adacore.com> Date: Mon Mar 28 19:15:30 2022 -0400 [Ada] Subprogram renaming fails to hide homograph The compiler failed to detect an error where the first prefix of an expanded name given as the renamed subprogram in a subprogram renaming declaration denotes a unit with the same name as the name given for the subprogram renaming. Such a unit must be hidden by the renaming itself. An error check is added to catch this case. gcc/ada/ * sem_ch8.adb (Analyze_Subprogram_Renaming): Add error check for the case of a renamed subprogram given by an expanded name whose outermost prefix names a unit that is hidden by the name of the renaming. (Ult_Expanded_Prefix): New local expression function to return the ultimate prefix of an expanded name. Diff: --- gcc/ada/sem_ch8.adb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb index 60c2ce6e3bc..1cf34117a30 100644 --- a/gcc/ada/sem_ch8.adb +++ b/gcc/ada/sem_ch8.adb @@ -3967,6 +3967,31 @@ package body Sem_Ch8 is ("implicit operation& is not visible (RM 8.3 (15))", Nam, Old_S); end if; + + -- Check whether an expanded name used for the renamed subprogram + -- begins with the same name as the renaming itself, and if so, + -- issue an error about the prefix being hidden by the renaming. + -- We exclude generic instances from this checking, since such + -- normally illegal renamings can be constructed when expanding + -- instantiations. + + elsif Nkind (Nam) = N_Expanded_Name then + declare + function Ult_Expanded_Prefix (N : Node_Id) return Node_Id is + (if Nkind (N) /= N_Expanded_Name + then N + else Ult_Expanded_Prefix (Prefix (N))); + -- Returns the ultimate prefix of an expanded name + + begin + if Chars (Entity (Ult_Expanded_Prefix (Nam))) = Chars (New_S) + and then not In_Instance + then + Error_Msg_Sloc := Sloc (N); + Error_Msg_NE + ("& is hidden by declaration#", Nam, New_S); + end if; + end; end if; Set_Convention (New_S, Convention (Old_S));
reply other threads:[~2022-05-17 8:29 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=20220517082945.6E0983857407@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).