From patchwork Wed Jul 4 21:31:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 169049 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 791E92C0089 for ; Thu, 5 Jul 2012 07:31:58 +1000 (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=1342042319; 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=CawAcn2 eezXvaN2gHtTfvyztZQc=; b=IScyxC7w6O/183xs39jHDJ9E/eqGjPj2lGi+irX s7eCK3FVRGkZ0ZG4X1QEsFobokuGToaUB5eAx2owtAyFT8Kls7Q2NeV9kqIRVfrG lYmWSwCqFHoB73rbKTnat+IvzYnQb8HMMh8xBd93EuQISQiDfeUbtTu5tv8TchRE Up2I= 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=cbweo+QlHwQWMmoXbB2v3kf91e0ut9fpCbHNRYsZ/LsVV5/zsNNEZloLzTEiTU +/D7cz5bNYcs9ypN6sLli8epVzKRqL3dAvlzx+OhTpVS6mDA2fe3Vb0Ojlf09URf rGdE64hyCrGpH7mWRLkAtYsE3yvKU3EMpfS+Q1hso2FPk=; Received: (qmail 14108 invoked by alias); 4 Jul 2012 21:31:54 -0000 Received: (qmail 14094 invoked by uid 22791); 4 Jul 2012 21:31:53 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, 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, 04 Jul 2012 21:31:37 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q64LVbUG011652 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 4 Jul 2012 17:31:37 -0400 Received: from [10.3.113.45] (ovpn-113-45.phx2.redhat.com [10.3.113.45]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q64LVaBt019770 for ; Wed, 4 Jul 2012 17:31:36 -0400 Message-ID: <4FF4B638.6070403@redhat.com> Date: Wed, 04 Jul 2012 17:31:36 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/53848 (ICE with enum in class in extern "C") 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 retrofit_lang_decl now wants to look at the DECL_CONTEXT of an enumerator, but we were calling it before setting the context. The comment before the call to build_lang_decl_loc mentions DECL_CLASS_CONTEXT, but that macro doesn't use DECL_LANG_SPECIFIC anymore, so I decided to check whether we really need DECL_LANG_SPECIFIC for enumerators anymore. Regression testing suggests that we don't. Tested x86_64-pc-linux-gnu, applying to trunk. commit 8db4cb20608874c36ba4112fb30d718a09e425ff Author: Jason Merrill Date: Wed Jul 4 15:57:36 2012 -0400 PR c++/53848 * decl.c (build_enumerator): Don't use build_lang_decl_loc. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 18beaa9..b8dcd03 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -12561,20 +12561,20 @@ incremented enumerator value is too large for %"); course, if we're processing a template, there may be no value. */ type = value ? TREE_TYPE (value) : NULL_TREE; - if (context && context == current_class_type) - /* This enum declaration is local to the class. We need the full - lang_decl so that we can record DECL_CLASS_CONTEXT, for example. */ - decl = build_lang_decl_loc (loc, CONST_DECL, name, type); - else - /* It's a global enum, or it's local to a function. (Note local to - a function could mean local to a class method. */ - decl = build_decl (loc, CONST_DECL, name, type); + decl = build_decl (loc, CONST_DECL, name, type); DECL_CONTEXT (decl) = enumtype; TREE_CONSTANT (decl) = 1; TREE_READONLY (decl) = 1; DECL_INITIAL (decl) = value; +#if 0 + if (context && context == current_class_type) + /* This enum declaration is local to the class. We need the full + lang_decl so that we can record DECL_CLASS_CONTEXT, for example. */ + retrofit_lang_decl (decl); +#endif + if (context && context == current_class_type && !SCOPED_ENUM_P (enumtype)) /* In something like `struct S { enum E { i = 7 }; };' we put `i' on the TYPE_FIELDS list for `S'. (That's so that you can say diff --git a/gcc/testsuite/g++.dg/other/enum3.C b/gcc/testsuite/g++.dg/other/enum3.C new file mode 100644 index 0000000..23d6c83 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/enum3.C @@ -0,0 +1,10 @@ +// PR c++/53848 + +extern "C" +{ + struct s { + enum { + e = 0 + } f; + }; +}