From patchwork Tue May 2 09:06:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 757478 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 3wHFmC2vLcz9s5L for ; Tue, 2 May 2017 19:07:06 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="b2JlYxLc"; 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=FmXcEFZBGoHo6dTDYTQs6pFLOpFGfdAFT+ljNM17C+mfgOlk8C 9mcbfiDi0Sl5oFGF6CYG/J5VB0wRmKDgg2tADzz9tWFhh0wYAviox4bq9MtAZgAD ipeoi9gG61GpYB4f6oHm3i3QfrSsei4Me0T3w8Dm2PXLZgaCNIdV9yKyM= 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=jErdpICN2ejInHpjwyXBey+3m0I=; b=b2JlYxLcehrhAVDlTfmh sHbzZQJ9UR4jsQz/EDCjolbQgL4WnT+4jQvwfmS6GTUAAwb189XJBRLCMmBND9Ua ory9dThkgl+M23z64kv5QqyQK3rkCsCugMe7xzBXoXqVn1cDLPyzAAw8uoUxOlXm CJlE7CnecMDyVNLPYLaQmD8= Received: (qmail 93976 invoked by alias); 2 May 2017 09:06:54 -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 91043 invoked by uid 89); 2 May 2017 09:06:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=orange, Orange, yellow 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 ESMTP; Tue, 02 May 2017 09:06:48 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id AAE349EDD; Tue, 2 May 2017 05:06:49 -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 moUnOzQ0AJ+S; Tue, 2 May 2017 05:06:49 -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 71C2D9ED8; Tue, 2 May 2017 05:06:49 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4192) id 6F0204FF; Tue, 2 May 2017 05:06:49 -0400 (EDT) Date: Tue, 2 May 2017 05:06:49 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [Ada] Missing error on T'Enum_Rep with no parameter Message-ID: <20170502090649.GA75302@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) This patch fixes a bug in which the compiler fails to give an error on T'Enum_Rep, where T is a type. If X is an object of enumeration type T, then X'Enum_Rep and T'Enum_Rep(X) are allowed, but not T'Enum_Rep. The following test must get an error. enum_val_test.adb:4:21: prefix of "Enum_Rep" attribute must be discrete object procedure Enum_Val_Test is type Color is (Red, Orange, Yellow); Current_Index : Color := Orange; Rep : Integer := Color'Enum_Rep; -- Illegal! begin null; end Enum_Val_Test; Tested on x86_64-pc-linux-gnu, committed on trunk 2017-05-02 Bob Duff * sem_attr.adb (Attribute_Enum_Rep): Disallow T'Enum_Rep. Index: sem_attr.adb =================================================================== --- sem_attr.adb (revision 247479) +++ sem_attr.adb (working copy) @@ -3763,13 +3763,23 @@ -------------- when Attribute_Enum_Rep => + -- T'Enum_Rep (X) case + if Present (E1) then Check_E1; Check_Discrete_Type; Resolve (E1, P_Base_Type); - elsif not Is_Discrete_Type (Etype (P)) then - Error_Attr_P ("prefix of % attribute must be of discrete type"); + -- X'Enum_Rep case. X must be an object or enumeration literal, and + -- it must be of a discrete type. + + elsif not ((Is_Object_Reference (P) + or else (Is_Entity_Name (P) + and then Ekind (Entity (P)) = + E_Enumeration_Literal)) + and then Is_Discrete_Type (Etype (P))) + then + Error_Attr_P ("prefix of % attribute must be discrete object"); end if; Set_Etype (N, Universal_Integer);