This is the mail archive of the 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]

[Ada] Loop parameter is a constant in an iterator over a formal container.

This patch enforces the same semantics for the handling of loop parameters
in element iterators over formal containers, os those over formal containers:
the loop parameter cannot be assigned to in user code.

Compiling formal_test.adb must yield:

   formal_test.adb:15:07: assignment to loop parameter not allowed

with Ada.Containers.Formal_Doubly_Linked_Lists;
procedure Formal_Test is
   type E is range 1 .. 1000;
   package My_List is new Ada.Containers.Formal_Doubly_Linked_Lists (E);
   use My_List;
   Thing : My_List.List (10);
   C : Cursor;
   for I in 1 .. 10 loop
      Append (Thing, E (I));
   end loop;

   for Element of Thing loop
      Element := Element * 3;  --  ERROR
   end loop;

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-10-10  Ed Schonberg  <>

	* exp_ch5.adb (Expand_Formal_Container_Element_Loop): Analyze
	declaration for loop parameter before rest of loop, and set
	entity kind to prevent assignments to it in the user code.
	* sem_ch3.adb (Analyze_Object_Contract): No contracts apply to the
	loop parameter in an element iteration over o formal container.

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]