public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: vasilche@ncbi.nlm.nih.gov To: gcc-gnats@gcc.gnu.org Cc: vakatov@ncbi.nlm.nih.gov, kuznets@ncbi.nlm.nih.gov Subject: c++/9946: destructor is not called for temporary object Date: Tue, 04 Mar 2003 20:26:00 -0000 [thread overview] Message-ID: <20030304202114.26013.qmail@sources.redhat.com> (raw) >Number: 9946 >Category: c++ >Synopsis: destructor is not called for temporary object >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Tue Mar 04 20:26:01 UTC 2003 >Closed-Date: >Last-Modified: >Originator: vasilche@ncbi.nlm.nih.gov >Release: gcc-3.2.2 >Organization: >Environment: Linux linus 2.4.17-aa #6 SMP Thu Jan 3 17:53:55 EST 2002 i686 unknown >Description: If expression of type 'const C' (not const reference) is passed to function accepting 'C' by value, gcc 3.2.0-3.2.2 doesn't call destructor for temporary argument object. ---- The code destr.cpp: #include <iostream> struct C { C(void) { std::cerr << this << "->C()\n"; } C(const C& c) { std::cerr << this << "->C(" << &c << ")\n"; } ~C(void) { std::cerr << this << "->~C()\n"; } }; struct C2 { const C get(void) const { return c; } void go(C c) {} C c; }; int main() { C2 c2; c2.go(c2.get()); } ---- Command line: # g++ -O0 -o destr destr.cpp ---- Output: ~/tmp# ./destr 0xbffff604->C() 0xbffff5f4->C(0xbffff604) 0xbffff604->~C() ~/tmp# >How-To-Repeat: Returned object value should be const. Argument should be object by value. Compilation should be without optimization. With optimization turned on all destructors are called correctly. >Fix: >Release-Note: >Audit-Trail: >Unformatted:
reply other threads:[~2003-03-04 20:26 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20030304202114.26013.qmail@sources.redhat.com \ --to=vasilche@ncbi.nlm.nih.gov \ --cc=gcc-gnats@gcc.gnu.org \ --cc=kuznets@ncbi.nlm.nih.gov \ --cc=vakatov@ncbi.nlm.nih.gov \ /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).