From patchwork Wed Sep 15 23:59:07 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 64928 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 503F9B6EF7 for ; Thu, 16 Sep 2010 09:59:16 +1000 (EST) Received: (qmail 14619 invoked by alias); 15 Sep 2010 23:59:14 -0000 Received: (qmail 14607 invoked by uid 22791); 15 Sep 2010 23:59:14 -0000 X-SWARE-Spam-Status: No, hits=-6.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 15 Sep 2010 23:59:10 +0000 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o8FNx8wZ030183 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 15 Sep 2010 19:59:08 -0400 Received: from [127.0.0.1] ([10.3.113.13]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o8FNx7rJ004823 for ; Wed, 15 Sep 2010 19:59:07 -0400 Message-ID: <4C915DCB.4080907@redhat.com> Date: Wed, 15 Sep 2010 19:59:07 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.12) Gecko/20100912 Lightning/1.0b1 Shredder/3.0.8pre MIME-Version: 1.0 To: gcc-patches List Subject: C++0x PATCH to grokbitfield 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 We were failing to diagnose use of a scoped enum as a bit-field width. Tested x86_64-pc-linux-gnu, applied to trunk. commit bb4f84e102b0828f0318c1b64dbb2025d5b4acc4 Author: Jason Merrill Date: Wed Sep 15 15:25:12 2010 -0400 * decl2.c (grokbitfield): Diagnose non-integral width. diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index f233055..63197705 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -1066,6 +1066,10 @@ grokbitfield (const cp_declarator *declarator, if (width != error_mark_node) { + /* The width must be an integer type. */ + if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (width))) + error ("width of bit-field %qD has non-integral type %qT", value, + TREE_TYPE (width)); constant_expression_warning (width); DECL_INITIAL (value) = width; SET_DECL_C_BIT_FIELD (value); diff --git a/gcc/testsuite/g++.dg/cpp0x/scoped_enum2.C b/gcc/testsuite/g++.dg/cpp0x/scoped_enum2.C new file mode 100644 index 0000000..e87b36a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/scoped_enum2.C @@ -0,0 +1,11 @@ +// { dg-options -std=c++0x } + +enum class E { e = 10 }; +enum E2 { e2 = 10 }; + +struct C { + int arr[E::e]; // { dg-error "non-integral type" } + int arr2[E2::e2]; // OK + int i: E::e; // { dg-error "non-integral type" } + int i2: E2::e2; // OK +};