public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: Richard Smith <richard@ex-parrot.com> To: mmitchel@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, Subject: Re: c++/6057: expression mangling doesn't work for operator new Date: Fri, 13 Sep 2002 09:46:00 -0000 [thread overview] Message-ID: <20020913164602.27479.qmail@sources.redhat.com> (raw) The following reply was made to PR c++/6057; it has been noted by GNATS. From: Richard Smith <richard@ex-parrot.com> To: <nathan@gcc.gnu.org>, <gcc-bugs@gcc.gnu.org>, <gcc-prs@gcc.gnu.org>, <mmitchel@gcc.gnu.org>, <richard@ex-parrot.com>, <gcc-gnats@gcc.gnu.org> 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 <unsigned int> struct helper {}; template <class T> static void check( helper< sizeof( new T ) > * ); int main() { check<int>(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 <unsigned int> struct helper {}; template <class T> static void check( helper< sizeof( new(f) T(0) ) > * ); int main() { check<int>(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 <class T> T make_type(); template <unsigned int> struct helper {}; template <class T> static void check( helper< sizeof( make_type<T>() ) > * ); int main() { check<int>(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
next reply other threads:[~2002-09-13 16:46 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-09-13 9:46 Richard Smith [this message] -- strict thread matches above, loose matches on Subject: below -- 2002-09-13 7:28 nathan 2002-03-26 10:40 mmitchel 2002-03-26 2:16 richard
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20020913164602.27479.qmail@sources.redhat.com \ --to=richard@ex-parrot.com \ --cc=gcc-prs@gcc.gnu.org \ --cc=mmitchel@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).