aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2020-11-10 10:16:49 -0500
committerPierre-Marie de Rodat <derodat@adacore.com>2020-11-30 09:16:17 -0500
commit4056d9abfa67e3584f68e1c2ecb8de9bc05a68cf (patch)
tree91e5ed194b071715f788090a92387b5148f44b73
parent602c7bc2153591941a1f3c0edc4cb370910d2d95 (diff)
downloadgcc-4056d9abfa67e3584f68e1c2ecb8de9bc05a68cf.zip
gcc-4056d9abfa67e3584f68e1c2ecb8de9bc05a68cf.tar.gz
gcc-4056d9abfa67e3584f68e1c2ecb8de9bc05a68cf.tar.bz2
[Ada] Spurious error on iterator over container with modified private part
gcc/ada/ * exp_ch5.adb (Expand_Iterator_Loop_Over_Container): Check the signature of the private operation Get_Element_Access to prevent accidental use of a user-defined homonym subprogram.
-rw-r--r--gcc/ada/exp_ch5.adb13
1 files changed, 12 insertions, 1 deletions
diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb
index e720656..307acaa 100644
--- a/gcc/ada/exp_ch5.adb
+++ b/gcc/ada/exp_ch5.adb
@@ -4346,10 +4346,21 @@ package body Exp_Ch5 is
Iter_Pack := Scope (Root_Type (Etype (Iter_Type)));
-- Find declarations needed for "for ... of" optimization
+ -- These declarations come from GNAT sources or sources
+ -- derived from them. User code may include additional
+ -- overloadings with similar names, and we need to perforn
+ -- some reasonable resolution to find the needed primitives.
+ -- It is unclear whether this mechanism is fragile if a user
+ -- makes arbitrary changes to the private part of a package
+ -- that supports iterators.
Ent := First_Entity (Pack);
while Present (Ent) loop
- if Chars (Ent) = Name_Get_Element_Access then
+ if Chars (Ent) = Name_Get_Element_Access
+ and then Present (First_Formal (Ent))
+ and then Chars (First_Formal (Ent)) = Name_Position
+ and then No (Next_Formal (First_Formal (Ent)))
+ then
Fast_Element_Access_Op := Ent;
elsif Chars (Ent) = Name_Step