From patchwork Tue May 15 09:38:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 159277 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 5E9F6B6FB4 for ; Tue, 15 May 2012 19:38:59 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1337679539; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=26Iv7+80vSS7y3xiTXXC 8yf+c+w=; b=BuNFlo01hNL/W8WgkUtqB5nLjjQHW81ZajO8XbI7ABvF+J30rw18 WBYP3uLFCogc6P6sB9w5GoMFDhSeGzujBZPkRaUqPxVC6h0nEYIar67evX0cDtxh /GnQJLlrXZpYbmVGG1DP+gHL2RzkdZAoCCoIg49sN7u/5V8mjMnvViU= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=baaHx3rbPg4YwL1Zrhw1Gr2RMC8GnXNd6h+zysFJvkyU7xlh4c0KNcV6A4RrB9 tb+AfGhpfvuWwbdySOlPdZf4smLal3s/984ggTH7v2Y3LZB2+Y7juzAIPGdyYQGl 9+JA+BzbUCI2DpfaNhIAjIAHazRHn2jQ9WbQTuQ39ms9g=; Received: (qmail 15831 invoked by alias); 15 May 2012 09:38:34 -0000 Received: (qmail 15666 invoked by uid 22791); 15 May 2012 09:38:31 -0000 X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL 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; Tue, 15 May 2012 09:38:11 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 20E6C1C6A3B; Tue, 15 May 2012 05:38:11 -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 4vBzlRyEbxw1; Tue, 15 May 2012 05:38:11 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id D66991C6703; Tue, 15 May 2012 05:38:10 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id D6C4D92BF6; Tue, 15 May 2012 05:38:10 -0400 (EDT) Date: Tue, 15 May 2012 05:38:10 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Case statements over predicated subtypes Message-ID: <20120515093810.GA851@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 Ada 2012, if a subtype has a static predicate the set of its possible values is known statically and those are the alternatives that must be covered in in case statement. If the subtype has dynamic predicates, the alternatives must cover all values of the base type. Compiling nonstaticcase.adb in Ada 2012 mode must yield: nonstaticcase.adb:7:04: missing case values: -16#8000_0000# .. 0 nonstaticcase.adb:7:04: missing case values: 11 .. 16#7FFF_FFFF# nonstaticcase.adb:7:09: bounds of "rr" are not static, alternatives must cover base type --- procedure nonstaticcase (rmin : integer) is subtype r is integer range 1 .. 10 with Dynamic_Predicate => r >= rmin; rr : r; begin rr := rmin + 1; case rr is when 1 .. 10 => null; end case; end; Tested on x86_64-pc-linux-gnu, committed on trunk 2012-05-15 Ed Schonberg * sem_case.adb (Analyze_Choices): If the subtype of the expression has a non-static predicate, the case alternatives must cover the base type. Index: sem_case.adb =================================================================== --- sem_case.adb (revision 187501) +++ sem_case.adb (working copy) @@ -803,8 +803,18 @@ -- bounds of its base type to determine the values covered by the -- discrete choices. + -- In Ada 2012, if the subtype has a non-static predicate the full + -- range of the base type must be covered as well. + if Is_OK_Static_Subtype (Subtyp) then - Bounds_Type := Subtyp; + if not Has_Predicates (Subtyp) + or else Present (Static_Predicate (Subtyp)) + then + Bounds_Type := Subtyp; + else + Bounds_Type := Choice_Type; + end if; + else Bounds_Type := Choice_Type; end if;