From patchwork Fri May 24 17:25:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 246240 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id A3D402C02A4 for ; Sat, 25 May 2013 03:25:20 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=IhTpvdv0XANqCB8wE 4vA0SfUwmXIy4zNZfXx0Remue3XYgFJYlImj00hh8P1aQFAHf0y/sAxSyvFoZw+t L1fsUe6SLpQzOhGzZjm7rlL8vMqWxbC8GzCjVxSMgPMc4ZKzlEspWkTBXf+R9Pxz zBJzrkSeM5QJPDAJpDM5RE1Gmk= 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 :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=UD0WInROUYRq+7CpfqumvFy vWcI=; b=I4A/l+3md7NvTSvRXnmxxMSLVHXL+8T4VcSjVQmvj2uOOHTdAJD5Qxl LqMqiVdEzL9nEqtwJZI1GHkzClp9i9vGLSDWV5Q+q15sFH+NVyjfhJSK1HqtEftS WpX16I2wV/WzSP7L0D51DW7uCiuwRw6o5WQJrLEMiE96Ac58kj5I= Received: (qmail 5827 invoked by alias); 24 May 2013 17:25:14 -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 5816 invoked by uid 89); 24 May 2013 17:25:14 -0000 X-Spam-SWARE-Status: No, score=-6.6 required=5.0 tests=AWL, BAYES_00, KHOP_THREADED, RCVD_IN_DNSWL_MED, RCVD_IN_HOSTKARMA_NO, RP_MATCHES_RCVD, SPF_PASS, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 24 May 2013 17:25:14 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r4OHP9Nm000813 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 24 May 2013 17:25:10 GMT Received: from userz7022.oracle.com (userz7022.oracle.com [156.151.31.86]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r4OHPA8t016313 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 24 May 2013 17:25:11 GMT Received: from abhmt107.oracle.com (abhmt107.oracle.com [141.146.116.59]) by userz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r4OHP97M021447; Fri, 24 May 2013 17:25:10 GMT Received: from poldo4.casa (/79.43.214.122) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 24 May 2013 10:25:09 -0700 Message-ID: <519FA273.7030001@oracle.com> Date: Fri, 24 May 2013 19:25:07 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: Jason Merrill CC: "gcc-patches@gcc.gnu.org" Subject: Re: [C++ Patch] PR 19618 References: <519F5C0C.2050204@oracle.com> <519F6CE2.2080406@redhat.com> <519F7E2B.9000201@oracle.com> <519F9171.2000302@redhat.com> In-Reply-To: <519F9171.2000302@redhat.com> X-Virus-Found: No Hi, On 05/24/2013 06:12 PM, Jason Merrill wrote: > On 05/24/2013 10:50 AM, Paolo Carlini wrote: >> + || ((TREE_CODE (type) == ENUMERAL_TYPE >> + && (tree_int_cst_lt >> + (TYPE_SIZE (ENUM_UNDERLYING_TYPE (type)), w))) >> + || (TREE_CODE (type) == BOOLEAN_TYPE >> + && tree_int_cst_lt (TYPE_SIZE (type), w)))) > > The size of the enum underlying type is the same as the size of the > enum itself, so I don't think you need to handle enum and bool > differently here. Yeah. Sorry for wasting your time on this. I'm finishing testing the below then. Thanks, Paolo. ///////////////////// Index: cp/class.c =================================================================== --- cp/class.c (revision 199302) +++ cp/class.c (working copy) @@ -3140,9 +3140,12 @@ check_bitfield_decl (tree field) error ("zero width for bit-field %q+D", field); w = error_mark_node; } - else if (compare_tree_int (w, TYPE_PRECISION (type)) > 0 - && TREE_CODE (type) != ENUMERAL_TYPE - && TREE_CODE (type) != BOOLEAN_TYPE) + else if ((TREE_CODE (type) != ENUMERAL_TYPE + && TREE_CODE (type) != BOOLEAN_TYPE + && compare_tree_int (w, TYPE_PRECISION (type)) > 0) + || ((TREE_CODE (type) == ENUMERAL_TYPE + || TREE_CODE (type) == BOOLEAN_TYPE) + && tree_int_cst_lt (TYPE_SIZE (type), w))) warning (0, "width of %q+D exceeds its type", field); else if (TREE_CODE (type) == ENUMERAL_TYPE && (0 > (compare_tree_int Index: testsuite/g++.dg/expr/bitfield12.C =================================================================== --- testsuite/g++.dg/expr/bitfield12.C (revision 0) +++ testsuite/g++.dg/expr/bitfield12.C (working copy) @@ -0,0 +1,19 @@ +// PR c++/19618 + +struct bset1 { + bool bit : sizeof(bool) * __CHAR_BIT__ + 1; // { dg-warning "exceeds" } +}; + +enum E {}; + +struct bset2 { + E bit : sizeof(E) * __CHAR_BIT__ + 1; // { dg-warning "exceeds" } +}; + +struct bset3 { + bool bit : sizeof(bool) * __CHAR_BIT__; +}; + +struct bset4 { + E bit : sizeof(E) * __CHAR_BIT__; +};