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-202] [Ada] Suggest use of First_Valid/Last_Valid on type with static predicate Date: Mon, 9 May 2022 09:32:36 +0000 (GMT) [thread overview] Message-ID: <20220509093236.AE166384B0C7@sourceware.org> (raw) https://gcc.gnu.org/g:655ca5aaa970bb5e6727a72be6c3ba9d9f9d5f09 commit r13-202-g655ca5aaa970bb5e6727a72be6c3ba9d9f9d5f09 Author: Yannick Moy <moy@adacore.com> Date: Wed Jan 19 11:19:50 2022 +0100 [Ada] Suggest use of First_Valid/Last_Valid on type with static predicate Attributes First_Valid/Last_Valid can be used on types with static predicate, instead of First/Last/Range. Include that suggestion in the corresponding error message. gcc/ada/ * sem_util.adb (Bad_Predicated_Subtype_Use): Add continuation message. Diff: --- gcc/ada/sem_util.adb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 1fc2c617afa..d76b5d93511 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -1719,6 +1719,31 @@ package body Sem_Util is Error_Msg_FE (Msg, N, Typ); end if; + -- Suggest to use First_Valid/Last_Valid instead of First/Last/Range + -- if the predicate is static. + + if not Has_Dynamic_Predicate_Aspect (Typ) + and then Has_Static_Predicate (Typ) + and then Nkind (N) = N_Attribute_Reference + then + declare + Aname : constant Name_Id := Attribute_Name (N); + Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname); + begin + case Attr_Id is + when Attribute_First => + Error_Msg_F ("\use attribute First_Valid instead", N); + when Attribute_Last => + Error_Msg_F ("\use attribute Last_Valid instead", N); + when Attribute_Range => + Error_Msg_F ("\use attributes First_Valid and " + & "Last_Valid instead", N); + when others => + null; + end case; + end; + end if; + -- Emit an optional suggestion on how to remedy the error if the -- context warrants it.
reply other threads:[~2022-05-09 9:32 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=20220509093236.AE166384B0C7@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).