This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/12737] Class destructor never gets invoked even though its corresponding class constructor is invoked, and the object has gone out of scope. (Appears to be related to copy-constructor initialization with an argument that consists of an implicit user-defined cast operator that returns a CONST value.)
- From: "bangerth at dealii dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 22 Oct 2003 23:09:14 -0000
- Subject: [Bug c++/12737] Class destructor never gets invoked even though its corresponding class constructor is invoked, and the object has gone out of scope. (Appears to be related to copy-constructor initialization with an argument that consists of an implicit user-defined cast operator that returns a CONST value.)
- References: <20031022224922.12737.da0g+@cs.cmu.edu>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12737
------- Additional Comments From bangerth at dealii dot org 2003-10-22 23:09 -------
Indeed. A reduced testcase is this:
----------------------------------------
#include <iostream>
struct Foo {
Foo() { std::cout << "foo constructor\n"; }
~Foo() { std::cout << "foo DESTRUCTOR\n"; }
Foo(const Foo & theFoo) { std::cout << "foo COPY-constructor\n"; }
};
struct Charlie {
Foo foo;
operator const Foo & () { return foo; }
};
static void bar ( Foo bar_foo ) {}
int main() {
Charlie charlie;
std::cout << "before call" << std::endl;
bar ( charlie );
std::cout << "after call" << std::endl;
}
---------------------------------------------
We fail to call the destructor on the temporary, but we do so with 3.3 and present
mainline. The bug is thus indeed fixed.
W.