From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12191 invoked by alias); 24 Oct 2008 19:31:26 -0000 Received: (qmail 12181 invoked by uid 22791); 24 Oct 2008 19:31:26 -0000 X-Spam-Check-By: sourceware.org Received: from smtp23.orange.fr (HELO smtp23.orange.fr) (193.252.22.126) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 24 Oct 2008 19:30:46 +0000 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2324.orange.fr (SMTP Server) with ESMTP id 809847000088; Fri, 24 Oct 2008 21:30:41 +0200 (CEST) Received: from [192.168.1.132] (ANice-252-1-39-37.w82-122.abo.wanadoo.fr [82.122.245.37]) by mwinf2324.orange.fr (SMTP Server) with ESMTP id 23D807000083; Fri, 24 Oct 2008 21:30:41 +0200 (CEST) X-ME-UUID: 20081024193041146.23D807000083@mwinf2324.orange.fr Message-ID: <49022260.8070307@users.sourceforge.net> Date: Fri, 24 Oct 2008 21:42:00 -0000 From: Simon Martin User-Agent: Thunderbird 2.0.0.17 (Macintosh/20080914) MIME-Version: 1.0 To: Mark Mitchell Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Fix PR c++/37647: ICE with invalid use of constructor References: <48E59333.8020004@users.sourceforge.net> <48F26C19.6080803@codesourcery.com> In-Reply-To: <48F26C19.6080803@codesourcery.com> Content-Type: multipart/mixed; boundary="------------060809000007030602080001" X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2008-10/txt/msg01078.txt.bz2 This is a multi-part message in MIME format. --------------060809000007030602080001 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 850 Hi Mark, >> The problem is that DECL_CONSTRUCTOR is set for "void A();", which >> implies that we call 'grok_ctor_properties' itself calling 'copy_fn_p', >> that asserts that the passed declaration "has" DECL_FUNCTION_MEMBER_P, >> which is obviously not the case here. > > Is there any way that we can avoid even getting the idea that this is an > sfk_constructor? Your patch seems like it's a bit later than we'd like; > we're concluding that the function is sfk_constructor and then backing > out when we notice that ctype is NULL. Can we just avoid concluding > this is a constructor at all? The attached patch does the check earlier and reports an error when encountering a constructor or a destructor in a non-class scope. I've successfully tested it on x86_64-apple-darwin-9. Is it better? OK for 4.3 and for the mainline? Thanks, Simon --------------060809000007030602080001 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="CL_37647" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="CL_37647" Content-length: 152 2008-10-24 Simon Martin PR c++/37647 * decl.c (grokdeclarator): Reject [con|de]stuctors in a non-class scope. --------------060809000007030602080001 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="pr37647_2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="pr37647_2.patch" Content-length: 651 Index: gcc/cp/decl.c =================================================================== --- gcc/cp/decl.c (revision 141326) +++ gcc/cp/decl.c (working copy) @@ -9252,6 +9252,14 @@ grokdeclarator (const cp_declarator *dec error ("virtual non-class function %qs", name); virtualp = 0; } + else if (sfk == sfk_constructor + || sfk == sfk_destructor) + { + error (funcdef_flag + ? "%qs defined in a non-class scope" + : "%qs declared in a non-class scope", name); + sfk = sfk_none; + } } else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2 && !NEW_DELETE_OPNAME_P (original_name)) --------------060809000007030602080001 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="CL_37647_testsuite" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="CL_37647_testsuite" Content-length: 112 2008-10-24 Simon Martin PR c++/37647 * g++.dg/parse/ctor9.C: New test. --------------060809000007030602080001 Content-Type: text/plain; name="ctor9.C" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ctor9.C" Content-length: 170 /* PR c++/37647 */ /* { dg-do "compile" } */ struct A { A() { void A(); } /* { dg-error "return type specification for constructor invalid|non-class scope" } */ }; --------------060809000007030602080001--