public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: niemayer@isg.de To: gcc-gnats@gcc.gnu.org Subject: c++/3615: unneccessary temporary instance created during function call Date: Mon, 09 Jul 2001 03:56:00 -0000 [thread overview] Message-ID: <20010709104755.16908.qmail@sourceware.cygnus.com> (raw) >Number: 3615 >Category: c++ >Synopsis: unneccessary temporary instance created during function call >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Mon Jul 09 03:56:00 PDT 2001 >Closed-Date: >Last-Modified: >Originator: Peter Niemayer >Release: gcc-3.0 >Organization: >Environment: i686-pc-linux-gnu >Description: When calling a function that takes a reference to a base class "base" with an argument that is an instance of a class that can be casted to a "class foo &" (where foo is derived from "base"), gcc3 tries to create a temporary "foo" instance without any reason and failing if copying of "foo" isn't allowed. >How-To-Repeat: compiling the following small code example with gcc2 works fine, with gcc-3.0 it results in the error: bug.cxx: In function `void bug()': bug.cxx:26: `foo::foo(const foo&)' is private bug.cxx:47: within this context bug.cxx:47: initializing temporary from result of `Ptr<T>::operator T&() [with T = foo]' bug.cxx:38: in passing argument 1 of `void func2(base&)' ---------- code sample ----------- template <class T> class Ptr { protected: T * ptr; public: Ptr(void) : ptr(0) { }; Ptr(T * p) : ptr(p) { }; ~Ptr(void) { delete ptr; } operator T & () { return *ptr; } }; class base { public: base(void) { } ~base(void) { } }; class foo : public base { private: foo(const foo & rv); // does not exist - no copy allowed! public: foo(void) { } ~foo(void) { } }; void func(foo & f) { // ... } void func2(base & b) { // ... } void bug(void) { Ptr<foo> f = new foo; func(f); // works as expected with gcc2 and gcc3 func2(f); // works with gcc2, creates an unneccessary // temporary instance with gcc-3.0 } ---------- code sample end ------------ >Fix: >Release-Note: >Audit-Trail: >Unformatted:
next reply other threads:[~2001-07-09 3:56 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2001-07-09 3:56 niemayer [this message] 2001-08-12 4:00 gdr 2001-11-15 12:26 mmitchel 2001-11-15 12:38 mmitchel
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=20010709104755.16908.qmail@sourceware.cygnus.com \ --to=niemayer@isg.de \ --cc=gcc-gnats@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).