From patchwork Wed Apr 20 10:51:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 612623 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qqdwh3Xr3z9t5T for ; Wed, 20 Apr 2016 20:51:31 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=jwGd1p8z; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=i6OfIzXV4qWKrU39961jmByWyGR8NJJRNYlAjEEI4N7sc+NLKj 8NAN3WrjJI33znsKcAFqFkak+IdohMqbOc7UleadxKEq/pDku3b5mHxJ540Yey+c feNUgH7M7zAu50A/iVY8dSu0aNnLOQAIY7ZSvjruMSyA2kZ19SMO0/HN0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=Ieou/hqQuKWuBVFAnHamg9AKN4E=; b=jwGd1p8z2JZm0i3up54d 0TGnyR2k7ujCrQUqNGJEKUImsdMM0YZxcUa8bc4gwUp8dfYDu040nzqUkR8DJ/uY OkVKWJOtktUDVh+5qzpwFnY859DuMTc+9GNoFqa/9DZzyrheturF8LHdfT0dPRDA VKWv+M3iaEDiFXumVz2KzMk= Received: (qmail 125565 invoked by alias); 20 Apr 2016 10:51:21 -0000 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 Received: (qmail 125546 invoked by uid 89); 20 Apr 2016 10:51:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.6 required=5.0 tests=BAYES_50, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.2 spammy=elsif, Nkind, nkind, Etype X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 20 Apr 2016 10:51:10 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 31B0E116C30; Wed, 20 Apr 2016 06:51:09 -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 5dy1CpaPCTPj; Wed, 20 Apr 2016 06:51:09 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) by rock.gnat.com (Postfix) with ESMTP id 1D459116C22; Wed, 20 Apr 2016 06:51:09 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4192) id 19B761A5; Wed, 20 Apr 2016 06:51:09 -0400 (EDT) Date: Wed, 20 Apr 2016 06:51:09 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Illegal use of current instance in attribute reference Message-ID: <20160420105109.GA3711@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) The current instance of a type in an aspect specification is an object of the type. If the type is scalar, it cannot be the prefix of an attribute reference such as 'First, whose prefix must an array object (even though it can be a scalar type in other contexts). Compiling foo.adb must yield: foo.adb:3:29: prefix of "First" attribute cannot be the current instance of a scalar type foo.adb:6:29: prefix of "First" attribute cannot be the current instance of a scalar type --- procedure Foo is type T_Data_Sending_Frequency is new Natural with Default_Value => T_Data_Sending_Frequency'First; type Infrequent is new Natural with Default_Value => Infrequent'First + 3; begin null; end; Tested on x86_64-pc-linux-gnu, committed on trunk 2016-04-20 Ed Schonberg * sem_attr.adb (Check_Type): Reject an attribute reference in an aspect expression, when the prefix of the reference is the current instance of the type to which the aspect applies. Index: sem_attr.adb =================================================================== --- sem_attr.adb (revision 235243) +++ sem_attr.adb (working copy) @@ -1408,10 +1408,41 @@ -------------------------------- procedure Check_Array_Or_Scalar_Type is + function In_Aspect_Specification return Boolean; + -- A current instance of a type in an aspect specification is an + -- object and not a type, and therefore cannot be of a scalar type + -- in the prefix of one of the array attributes if the attribute + -- reference is part of an aspect expression. + + ----------------------------- + -- In_Aspect_Specification -- + ----------------------------- + + function In_Aspect_Specification return Boolean is + P : Node_Id; + + begin + P := Parent (N); + while Present (P) loop + if Nkind (P) = N_Aspect_Specification then + return P_Type = Entity (P); + + elsif Nkind (P) in N_Declaration then + return False; + end if; + + P := Parent (P); + end loop; + + return False; + end In_Aspect_Specification; + + -- Local variables + + Dims : Int; Index : Entity_Id; - D : Int; - -- Dimension number for array attributes + -- Start of processing for Check_Array_Or_Scalar_Type begin -- Case of string literal or string literal subtype. These cases @@ -1431,6 +1462,12 @@ if Present (E1) then Error_Attr ("invalid argument in % attribute", E1); + + elsif In_Aspect_Specification then + Error_Attr + ("prefix of % attribute cannot be the current instance of a " + & "scalar type", P); + else Set_Etype (N, P_Base_Type); return; @@ -1466,9 +1503,9 @@ Set_Etype (N, Base_Type (Etype (Index))); else - D := UI_To_Int (Intval (E1)); + Dims := UI_To_Int (Intval (E1)); - for J in 1 .. D - 1 loop + for J in 1 .. Dims - 1 loop Next_Index (Index); end loop;