public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/9946: destructor is not called for temporary object
@ 2003-03-04 20:26 vasilche
  0 siblings, 0 replies; only message in thread
From: vasilche @ 2003-03-04 20:26 UTC (permalink / raw)
  To: gcc-gnats; +Cc: vakatov, kuznets


>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:


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-03-04 20:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-04 20:26 c++/9946: destructor is not called for temporary object vasilche

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).