[LLVMbugs] [Bug 11838] New: Clang fails to call temporary destructors in temporaries
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Mon Jan 23 11:38:40 PST 2012
http://llvm.org/bugs/show_bug.cgi?id=11838
Bug #: 11838
Summary: Clang fails to call temporary destructors in
temporaries
Product: clang
Version: unspecified
Platform: Macintosh
OS/Version: MacOS X
Status: NEW
Severity: release blocker
Priority: P
Component: C++
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: asomerfield at serif.com
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
Hi,
We've just hit a blocker with Clang+LLVM ("Apple Compiler 3.0") in the latest
XCode.
Basically, Clang does not call destructors of temporaries inside a templated
function. GCC+LLVM does not exhibit this behaviour.
Example:
#include <iostream>
class SomeObject
{
public:
SomeObject()
{
printf("Constructed\r\n");
}
SomeObject(const SomeObject& rhs)
{
printf("Copied\r\n");
}
~SomeObject()
{
printf("Destructed\r\n");
}
};
class Test
{
public:
template<typename T> // Comment me out to see working case
void DoTest()
{
GetObject();
}
SomeObject GetObject()
{
return m_object;
}
SomeObject m_object;
};
int main (int argc, const char * argv[])
{
// Works
//Test test;
//test.DoTest();
// Broken
Test test;
test.DoTest<int>();
return 0;
}
Running this code yields:
Constructed
Copied
Destructed
If you a.) Run this with GCC+LLVM OR b.) remove the template<typename T> and
comment in the "Works" code in main, you will get the correct output of:
Constructed
Copied
Destructed
Destructed
We noticed this while tracking down an issue in our code which manifested as
"ref-counted pointers failing to decrement sometimes :/" (imagine if
GetObject() returned a ref-counted object by value).
I don't think this is already fixed - I tried to find similar things in
BugZilla but got nothing - we are using the latest Xcode on latest Mac OS X
Lion using Sandybridge X86 hardware. The bug manifests in both -O0 (debug) and
-O3 (release) - which leads me to guess it's not a dead-code optimisation
problem.
Cheers,
A
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list