From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27525 invoked by alias); 13 Sep 2002 16:46:03 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 27480 invoked by uid 71); 13 Sep 2002 16:46:02 -0000 Date: Fri, 13 Sep 2002 09:46:00 -0000 Message-ID: <20020913164602.27479.qmail@sources.redhat.com> To: mmitchel@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Richard Smith Subject: Re: c++/6057: expression mangling doesn't work for operator new Reply-To: Richard Smith X-SW-Source: 2002-09/txt/msg00255.txt.bz2 List-Id: The following reply was made to PR c++/6057; it has been noted by GNATS. From: Richard Smith To: , , , , , Cc: Subject: Re: c++/6057: expression mangling doesn't work for operator new Date: Fri, 13 Sep 2002 17:45:49 +0100 (BST) On 13 Sep 2002 nathan@gcc.gnu.org wrote: > is this fixed now? No, the bug is still there in cvs on the mainline. Try, for example, compiling the following code template struct helper {}; template static void check( helper< sizeof( new T ) > * ); int main() { check(0); } The problem was with the new expression, not the sizeof expression. There was an unrelated bug with mangling of sizeof expression, which has now been fixed (can't find PR number at the moment); but that only applied where the argument of the sizeof expression was a type that was dependent on a template parameter, not an expression. The segfault is actually occuring on the line code = TREE_CODE (expr); // Line 1790 in revision 1.57 at the start of write_expression in mangle.c because expr is a NULL pointer. This is happening because when write_expression is called to write the NEW_EXPR it goes down the 'default' case statement at the end of the function, and iterates over each of the tree operands. The three operands to the NEW_EXPR tree node are the placement expresion (which is of type TREE_LIST, or, more frequently a NULL pointer), the type which is being created (which is a type not an expression), and the initialiser list (again, of type TREE_LIST, or a NULL pointer). The second operand of the NEW_EXPR needs to have write_type, not write_expression called on it; the first and third operands of NEW_EXPR need to be mangled in some new way, which is what the write_expression_list function in my patch does (it also copes with a NULL pointer argument, which write_expression doesn't). The following test case showes the other failure modes of the existing code struct foo {} f; typedef unsigned int size_t; void *operator new( size_t, foo ); template struct helper {}; template static void check( helper< sizeof( new(f) T(0) ) > * ); int main() { check(0); } where the segfault occurs because write_expression can't cope being passed a TREE_LIST. As I mentioned in the original PR, a more general solution would be preferable: I know that the same problems apply to function calls, template T make_type(); template struct helper {}; template static void check( helper< sizeof( make_type() ) > * ); int main() { check(0); } where the segfault occurs because CALL_EXPR's operands can't be handled. http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6057 -- Richard Smith