This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/9946: destructor is not called for temporary object


>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 at ncbi dot nlm dot nih dot 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:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]