From patchwork Fri May 24 12:24:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 246134 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 81EFD2C009E for ; Fri, 24 May 2013 22:24:58 +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:content-type; q=dns; s=default; b=VF8/ZvgWwn55cVWAVY5JoGbMWUeT7P82ziLAZt+gGha dEyQNeXj35g5EwLI0/D1/4Pj+92Z+qlxi3Z3lDmvxu5dzLKdgjGkq2NGigxH43UY JN283mViC/VzEXomENfdjNTtG4gwRoZs+ArqGhJ1EnK3GWFNFm00d8tWBnELQMrA = 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:content-type; s=default; bh=Z2KZhWio82GpioAcz93zOFdLSkU=; b=vg3UKAknijKlajcfF 5hHTqqOaZyVKO2CjYx8/U4SA58AvhJSXklcHN4ko79gcQphPq6Cclm1PqzQ2zHy0 fg8SUEJxQ2OvO5eWBoOcPmu26infycBVjWm2T77ztgwCj8s9uU/0gv6P+vJ64Wnm rCnai56Esxfi35XT+Q5HRLsKJk= Received: (qmail 16446 invoked by alias); 24 May 2013 12:24:52 -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 16435 invoked by uid 89); 24 May 2013 12:24:51 -0000 X-Spam-SWARE-Status: No, score=-5.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, SPF_PASS, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 24 May 2013 12:24:51 +0000 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r4OCOmo3021775 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 24 May 2013 12:24:48 GMT Received: from userz7021.oracle.com (userz7021.oracle.com [156.151.31.85]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r4OCOlIN028942 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 24 May 2013 12:24:47 GMT Received: from abhmt107.oracle.com (abhmt107.oracle.com [141.146.116.59]) by userz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r4OCOkik018443; Fri, 24 May 2013 12:24:46 GMT Received: from poldo4.casa (/79.43.214.122) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 24 May 2013 05:24:46 -0700 Message-ID: <519F5C0C.2050204@oracle.com> Date: Fri, 24 May 2013 14:24:44 +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: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 19618 X-Virus-Found: No Hi, I think we can resolve this very old issue too: we don't warn at all for bitfields of size exceeding the type when it's bool or enum. I have no idea why historically we decided to not do that, but certainly all the modern compilers I have at hand do warn, by default, thus it seems safe to at least pedwarn, or even simply warn, if you like. Patch booted and tested x86_64-linux. Thanks, Paolo. ////////////////////////// /cp 2013-05-24 Paolo Carlini PR c++/19618 * class.c (check_bitfield_decl): Pedwarn for bool and enum bitfields with width exceeding the type. /testsuite 2013-05-24 Paolo Carlini PR c++/19618 * g++.dg/expr/bitfield12.C: New. * g++.dg/expr/bitfield1.C: Adjust. * g++.dg/expr/bitfield3.C: Likewise. * g++.dg/expr/bitfield4.C: Likewise. * g++.dg/expr/bitfield5.C: Likewise. * g++.dg/expr/bitfield6.C: Likewise. * g++.old-deja/g++.jason/bool2.C: Likewise. Index: cp/class.c =================================================================== --- cp/class.c (revision 199287) +++ cp/class.c (working copy) @@ -3140,10 +3140,15 @@ 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) - warning (0, "width of %q+D exceeds its type", field); + else if (compare_tree_int (w, TYPE_PRECISION (type)) > 0) + { + if (TREE_CODE (type) == ENUMERAL_TYPE + || TREE_CODE (type) == BOOLEAN_TYPE) + pedwarn (input_location, OPT_Wpedantic, + "width of %q+D exceeds its type", field); + else + warning (0, "width of %q+D exceeds its type", field); + } else if (TREE_CODE (type) == ENUMERAL_TYPE && (0 > (compare_tree_int (w, TYPE_PRECISION (ENUM_UNDERLYING_TYPE (type)))))) Index: testsuite/g++.dg/expr/bitfield1.C =================================================================== --- testsuite/g++.dg/expr/bitfield1.C (revision 199288) +++ testsuite/g++.dg/expr/bitfield1.C (working copy) @@ -1,4 +1,5 @@ // PR c++/27505 +// { dg-options "" } struct s { bool field:8; 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,11 @@ +// PR c++/19618 + +struct bset1 { + bool bit : 93111; // { dg-error "exceeds" } +}; + +enum E {}; + +struct bset2 { + E bit : 93111; // { dg-error "exceeds" } +}; Index: testsuite/g++.dg/expr/bitfield3.C =================================================================== --- testsuite/g++.dg/expr/bitfield3.C (revision 199288) +++ testsuite/g++.dg/expr/bitfield3.C (working copy) @@ -1,4 +1,5 @@ // PR c++/30274 +// { dg-options "" } struct S { bool x : 4; Index: testsuite/g++.dg/expr/bitfield4.C =================================================================== --- testsuite/g++.dg/expr/bitfield4.C (revision 199288) +++ testsuite/g++.dg/expr/bitfield4.C (working copy) @@ -1,5 +1,6 @@ // PR c++/30274 // { dg-do link } +// { dg-options "" } struct S { bool x : 4; Index: testsuite/g++.dg/expr/bitfield5.C =================================================================== --- testsuite/g++.dg/expr/bitfield5.C (revision 199288) +++ testsuite/g++.dg/expr/bitfield5.C (working copy) @@ -1,5 +1,6 @@ // PR c++/30274 // { dg-do run } +// { dg-options "" } struct S { bool x : 4; Index: testsuite/g++.dg/expr/bitfield6.C =================================================================== --- testsuite/g++.dg/expr/bitfield6.C (revision 199288) +++ testsuite/g++.dg/expr/bitfield6.C (working copy) @@ -1,4 +1,5 @@ // PR c++/30274 +// { dg-options "" } struct S { bool x : 4; Index: testsuite/g++.old-deja/g++.jason/bool2.C =================================================================== --- testsuite/g++.old-deja/g++.jason/bool2.C (revision 199287) +++ testsuite/g++.old-deja/g++.jason/bool2.C (working copy) @@ -1,4 +1,5 @@ // { dg-do run } +// { dg-options "" } // Make sure that bool bitfields promote to int properly. struct F {