From patchwork Wed Dec 14 22:18:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 131485 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 48CBE1007D6 for ; Thu, 15 Dec 2011 09:18:51 +1100 (EST) Received: (qmail 26248 invoked by alias); 14 Dec 2011 22:18:49 -0000 Received: (qmail 26240 invoked by uid 22791); 14 Dec 2011 22:18:48 -0000 X-SWARE-Spam-Status: No, hits=-5.3 required=5.0 tests=AWL, BAYES_00, 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, 14 Dec 2011 22:18:33 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pBEMIXpq007357 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 14 Dec 2011 17:18:33 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pBEMIX8a029450 for ; Wed, 14 Dec 2011 17:18:33 -0500 Received: from [0.0.0.0] (ovpn-113-21.phx2.redhat.com [10.3.113.21]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id pBEMIWuc014980 for ; Wed, 14 Dec 2011 17:18:32 -0500 Message-ID: <4EE920B7.4030804@redhat.com> Date: Wed, 14 Dec 2011 17:18:31 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111112 Thunderbird/8.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/51248 (ICE with unusual enum) 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 I used to think that there was no way to get a variant of an enum before the end of the first mention of it. But when that's an enum-specifier that refers to a cv-variant of the type in one of the enumerator initializers, there is a way... Tested x86_64-pc-linux-gnu, applying to 4.6 and trunk. commit cfd4ae9cf58950ccd4f374bc0489e4a8b7bdffe7 Author: Jason Merrill Date: Wed Dec 14 13:37:16 2011 -0500 PR c++/51248 * decl.c (copy_type_enum): Also update variants. (finish_enum): Allow variants of complete enums. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 5a4e027..480d211 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -11908,15 +11908,19 @@ xref_basetypes (tree ref, tree base_list) static void copy_type_enum (tree dst, tree src) { - TYPE_MIN_VALUE (dst) = TYPE_MIN_VALUE (src); - TYPE_MAX_VALUE (dst) = TYPE_MAX_VALUE (src); - TYPE_SIZE (dst) = TYPE_SIZE (src); - TYPE_SIZE_UNIT (dst) = TYPE_SIZE_UNIT (src); - SET_TYPE_MODE (dst, TYPE_MODE (src)); - TYPE_PRECISION (dst) = TYPE_PRECISION (src); - TYPE_ALIGN (dst) = TYPE_ALIGN (src); - TYPE_USER_ALIGN (dst) = TYPE_USER_ALIGN (src); - TYPE_UNSIGNED (dst) = TYPE_UNSIGNED (src); + tree t; + for (t = dst; t; t = TYPE_NEXT_VARIANT (t)) + { + TYPE_MIN_VALUE (t) = TYPE_MIN_VALUE (src); + TYPE_MAX_VALUE (t) = TYPE_MAX_VALUE (src); + TYPE_SIZE (t) = TYPE_SIZE (src); + TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (src); + SET_TYPE_MODE (dst, TYPE_MODE (src)); + TYPE_PRECISION (t) = TYPE_PRECISION (src); + TYPE_ALIGN (t) = TYPE_ALIGN (src); + TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (src); + TYPE_UNSIGNED (t) = TYPE_UNSIGNED (src); + } } /* Begin compiling the definition of an enumeration type. @@ -12285,9 +12289,12 @@ finish_enum (tree enumtype) return; } - /* Here there should not be any variants of this type. */ + /* If this is a forward declaration, there should not be any variants, + though we can get a variant in the middle of an enum-specifier with + wacky code like 'enum E { e = sizeof(const E*) };' */ gcc_assert (enumtype == TYPE_MAIN_VARIANT (enumtype) - && !TYPE_NEXT_VARIANT (enumtype)); + && (TYPE_VALUES (enumtype) + || !TYPE_NEXT_VARIANT (enumtype))); } /* Build and install a CONST_DECL for an enumeration constant of the diff --git a/gcc/testsuite/g++.dg/other/enum2.C b/gcc/testsuite/g++.dg/other/enum2.C new file mode 100644 index 0000000..3a28f25 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/enum2.C @@ -0,0 +1,3 @@ +// PR c++/51248 + +enum E { e = sizeof(const E*) };