From patchwork Wed Feb 13 14:22:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 220146 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 65CB22C0292 for ; Thu, 14 Feb 2013 01:22:43 +1100 (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=1361370163; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=fdwEPFU IF5rcl7K8hf24gGoWVLg=; b=kezIKnFI1DAiw1hHZVzLF8NYYSMWEjhTXHKRabx yIOUWXEbzONcgxCCCDe1orCOtuF5UJvnNB6CPMZyeRB80bWxxVy1K86tc5yXWvVH mJH0L9TNGoMBJF1CCp/V7z9mQY2iNNdo3WcIeNkAeVRoHI80j7n84/QQw7gGi0JN fbUE= 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:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=MJ5fvucELS7DbOVwI+sVyZupE4QAxwONdoQaC2dkjo+dJeDhdoUTCnx1E4JV8L UT67yNoT9uqL9hLXfoIBOwfjjvge1NkblKrw4KitJRSv6sBrsmoM8T9H7A/JPslA DajajjnFDrU+IePXTAmhDB4EucD+wXAbJGda1CFb1+Xvs=; Received: (qmail 12783 invoked by alias); 13 Feb 2013 14:22:32 -0000 Received: (qmail 12768 invoked by uid 22791); 13 Feb 2013 14:22:30 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS 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, 13 Feb 2013 14:22:23 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1DEMMA7007785 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 13 Feb 2013 09:22:23 -0500 Received: from [10.3.113.24] (ovpn-113-24.phx2.redhat.com [10.3.113.24]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r1DEML87018163 for ; Wed, 13 Feb 2013 09:22:22 -0500 Message-ID: <511BA19D.1060602@redhat.com> Date: Wed, 13 Feb 2013 09:22:21 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Thunderbird/21.0a1 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/56155 (wrong type for enumerator) 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 Within the { } of an enum-specifier with a fixed underlying type, the enumerators are supposed to have that type. A comment in build_enumerator mentioned that requirement, but nothing actually implemented it. Tested x86_64-pc-linux-gnu, applying to trunk. commit 4944c862e7cd742a4d963bc50ce4ac10707d686b Author: Jason Merrill Date: Tue Feb 12 22:07:34 2013 -0500 PR c++/56155 * decl.c (build_enumerator): Always convert the value to a fixed underlying type. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 5a9ad2c..eb6c490 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -12786,15 +12786,14 @@ incremented enumerator value is too large for %"); does not fit, the program is ill-formed [C++0x dcl.enum]. */ if (ENUM_UNDERLYING_TYPE (enumtype) && value - && TREE_CODE (value) == INTEGER_CST - && !int_fits_type_p (value, ENUM_UNDERLYING_TYPE (enumtype))) + && TREE_CODE (value) == INTEGER_CST) { - error ("enumerator value %E is too large for underlying type %<%T%>", - value, ENUM_UNDERLYING_TYPE (enumtype)); + if (!int_fits_type_p (value, ENUM_UNDERLYING_TYPE (enumtype))) + error ("enumerator value %E is too large for underlying type %<%T%>", + value, ENUM_UNDERLYING_TYPE (enumtype)); - /* Silently convert the value so that we can continue. */ - value = perform_implicit_conversion (ENUM_UNDERLYING_TYPE (enumtype), - value, tf_none); + /* Convert the value to the appropriate type. */ + value = convert (ENUM_UNDERLYING_TYPE (enumtype), value); } } diff --git a/gcc/testsuite/g++.dg/cpp0x/enum22.C b/gcc/testsuite/g++.dg/cpp0x/enum22.C new file mode 100644 index 0000000..e87a31c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/enum22.C @@ -0,0 +1,12 @@ +// PR c++/56155 +// { dg-do compile { target c++11 } } + +enum e_ : unsigned char { Z_, E_=sizeof(Z_) }; +static_assert( E_ == 1, "E_ should be 1"); + +template +struct A { + enum e_ : unsigned char { Z_, E_=sizeof(Z_) }; +}; + +static_assert ( A::E_ == 1, "E_ should be 1");