diff options
author | Yannick Moy <moy@adacore.com> | 2022-01-19 11:19:50 +0100 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2022-05-09 09:27:39 +0000 |
commit | 655ca5aaa970bb5e6727a72be6c3ba9d9f9d5f09 (patch) | |
tree | 1df370a06f743d33c6b26c8a295a853467bffcae /gcc | |
parent | c32983082576e1452a19bc7df8901d6e6d9229c2 (diff) | |
download | gcc-655ca5aaa970bb5e6727a72be6c3ba9d9f9d5f09.zip gcc-655ca5aaa970bb5e6727a72be6c3ba9d9f9d5f09.tar.gz gcc-655ca5aaa970bb5e6727a72be6c3ba9d9f9d5f09.tar.bz2 |
[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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/sem_util.adb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 1fc2c61..d76b5d9 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. |