From patchwork Mon Sep 5 13:43:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 113366 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id C1202B6F76 for ; Mon, 5 Sep 2011 23:43:38 +1000 (EST) Received: (qmail 13088 invoked by alias); 5 Sep 2011 13:43:32 -0000 Received: (qmail 13078 invoked by uid 22791); 5 Sep 2011 13:43:29 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 05 Sep 2011 13:43:15 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 2A0FA2BB223; Mon, 5 Sep 2011 09:43:15 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id JKRWwVTYkuHX; Mon, 5 Sep 2011 09:43:15 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 149502BB220; Mon, 5 Sep 2011 09:43:15 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id 0ED0A3FEE8; Mon, 5 Sep 2011 09:43:15 -0400 (EDT) Date: Mon, 5 Sep 2011 09:43:15 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Illegal iterators over arrays Message-ID: <20110905134315.GA25859@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org In early versions of Ada, an illegal iterator of the form "for X in S" where S is an array, is most likely an attempt to iterate over the range of S, and this is the appropriate error message to emit. In Ada 2012, there is a new iterator specification form "for E of S", and the error message must indicate that the new form uses a different keyword. Compiling the following program in Ada 2012 mode must yield: main.adb:7:14: to iterate over the elements of an array, use "of" main.adb:15:14: to iterate over the elements of an array, use "of" Compiling with an earlier version of the language must yield; main.adb:7:14: missing Range attribute in iteration over an array main.adb:15:14: missing Range attribute in iteration over an array --- with Ada.Text_IO; with Tools; with Type_Declarations; package body Main is procedure Process is begin for Index in Tools.Result loop Ada.Text_IO.Put_Line (Tools.Result (Index)'Img); end loop; end Process; procedure Process2 is Ct : constant Type_Declarations.Array_Type := Tools.Result; begin for Index in Ct loop Ada.Text_IO.Put_Line (Tools.Result (Index)'Img); end loop; end Process2; end Main; -- with Type_Declarations; package Tools is function Result return Type_Declarations.Array_Type; end Tools; --- package Type_Declarations is type Integer_Type is new Integer; Ct_Max : constant := 40; type Large_Index_Type is new Integer range 0 .. Ct_Max; subtype Index_Type is Large_Index_Type range 1 .. Large_Index_Type'Last; type Array_Type is array (Index_Type range <>) of Integer_Type; end Type_Declarations; Tested on x86_64-pc-linux-gnu, committed on trunk 2011-09-05 Ed Schonberg * sem_ch5.adb (Analyze_Iteration_Specification): Improve error message on an iterator over an array. Index: sem_ch5.adb =================================================================== --- sem_ch5.adb (revision 178448) +++ sem_ch5.adb (working copy) @@ -2336,13 +2336,18 @@ if Is_Array_Type (Typ) then if Of_Present (N) then Set_Etype (Def_Id, Component_Type (Typ)); + + elsif Ada_Version < Ada_2012 then + Error_Msg_N + ("missing Range attribute in iteration over an array", N); + else Error_Msg_N ("to iterate over the elements of an array, use OF", N); -- Prevent cascaded errors - Set_Ekind (Def_Id, E_Constant); + Set_Ekind (Def_Id, E_Loop_Parameter); Set_Etype (Def_Id, Etype (First_Index (Typ))); end if;