This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
This patch fixes a visibility bug in the expansion of a loop over an object whose type carries the GNAT-specific Iterable aspect. Prior to this patch, the loop variable remained visible after exit from the loop. Compiling iterator_test.adb must yield: iterator_test.adb:26:61: "number" is not visible iterator_test.adb:26:61: non-visible declaration at line 21 iterator_test.adb:26:61: non-visible declaration at line 16 --- with Ada.Text_IO; with iterators; use iterators; procedure iterator_test is it_test : constant my_iterator := create_it(from => 3, to => 10); begin -- reference loop for number in 1 .. 10 loop Ada.Text_IO.Put_Line (Integer'Image (number)); end loop; -- gas day iterations Ada.Text_IO.Put_Line ("Test foreward iteration"); for number in it_test loop Ada.Text_IO.Put_Line (Integer'Image (number)); end loop; Ada.Text_IO.Put_Line ("Test backward iteration"); for number in create_it(from => 10, to => 3) loop Ada.Text_IO.Put_Line (Integer'Image (number)); end loop; Ada.Text_IO.Put_Line ("Out of scope?! " & Integer'Image (number)); end iterator_test; --- package iterators is type my_iterator is private with Iterable => (first => iterator_first, next => iterator_next, has_element => iterator_has_element); function create_it (from : Integer; to : Integer) return my_iterator; function iterator_first (it : my_iterator) return Integer; function iterator_next (it : my_iterator; prev_item : Integer) return Integer; function iterator_has_element (it : my_iterator; prev_item : Integer) return Boolean; private type my_iterator is record from : Integer; to : Integer; end record; end iterators; Tested on x86_64-pc-linux-gnu, committed on trunk 2017-12-05 Ed Schonberg <schonberg@adacore.com> * exp_ch5.adb (Expand_Formal_Container_Loop): Ensure that the loop parameter becomes invisible after analyzing the loop, which has been rewritten as a while-loop.
Attachment:
difs
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |