diff options
author | Gary Dismukes <dismukes@adacore.com> | 2020-06-07 19:41:15 -0400 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2020-07-16 05:18:08 -0400 |
commit | ebc2b117e43191de355187553586aef30048f098 (patch) | |
tree | 92e164376b99c97d3020ef94b28d5868c5140622 | |
parent | c6801105e167376e8839007a1539a8167fb09306 (diff) | |
download | gcc-ebc2b117e43191de355187553586aef30048f098.zip gcc-ebc2b117e43191de355187553586aef30048f098.tar.gz gcc-ebc2b117e43191de355187553586aef30048f098.tar.bz2 |
[Ada] Implicit dereferencing in container indexing
gcc/ada/
* sem_ch4.adb (Try_Container_Indexing): When the prefix type is
an access type, change it to the designated type, change the
prefix to an explicit dereference, and emit a ?d? warning for
the implicit dereference. Include a ??? comment questioning
whether this is the right context in which to perform the
implicit dereferencing.
-rw-r--r-- | gcc/ada/sem_ch4.adb | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb index 8c9a0bf..76ce11d 100644 --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -7979,7 +7979,7 @@ package body Sem_Ch4 is Prefix : Node_Id; Exprs : List_Id) return Boolean is - Pref_Typ : constant Entity_Id := Etype (Prefix); + Pref_Typ : Entity_Id := Etype (Prefix); function Constant_Indexing_OK return Boolean; -- Constant_Indexing is legal if there is no Variable_Indexing defined @@ -8415,6 +8415,25 @@ package body Sem_Ch4 is return True; end if; + -- An explicit dereference needs to be created in the case of a prefix + -- that's an access. + + -- It seems that this should be done elsewhere, but not clear where that + -- should happen. Normally Insert_Explicit_Dereference is called via + -- Resolve_Implicit_Dereference, called from Resolve_Indexed_Component, + -- but that won't be called in this case because we transform the + -- indexing to a call. Resolve_Call.Check_Prefixed_Call takes care of + -- implicit dereferencing and referencing on prefixed calls, but that + -- would be too late, even if we expanded to a prefix call, because + -- Process_Indexed_Component will flag an error before the resolution + -- happens. ??? + + if Is_Access_Type (Pref_Typ) then + Pref_Typ := Implicitly_Designated_Type (Pref_Typ); + Insert_Explicit_Dereference (Prefix); + Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N); + end if; + C_Type := Pref_Typ; -- If indexing a class-wide container, obtain indexing primitive from |