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]

[Ada] Rejecting properly illegal iterator


This patch removes an infinite loop in the compiler, when an Ada 2012 iterator
is attempted over an object without proper iterable aspects, and the code is
compiled in SPARK mode.

Compiling iter.adb must yield:

iter.adb:12:21: cannot iterate over "R"
iter.adb:12:21: to iterate directly over the elements of a container,
                write "of Obj"

---
procedure Iter is
   pragma SPARK_Mode (On);

   type R is record
     X, Y, Z : Integer;
   end record;

   Obj : R;
   function Sum (X : R) return Integer is
      Result : Integer := 0;
   begin
      return Result : Integer := 0  Do
         for Val in Obj loop
            Result := Result + Val;
         end loop;
      end return;
   end;
begin
   if Sum (Obj) /= 0 then
      null;
   end if;
end;

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

2014-11-07  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch5.adb (Analyze_Iterator_Specification): return if name
	in iterator does not have any usable aspect for iteration.

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]