Clang & C++ exceptions in destructors
Clang & C++ exceptions in destructors
- Subject: Clang & C++ exceptions in destructors
- From: Jesper Papmehl-Dufay <email@hidden>
- Date: Tue, 08 Jan 2013 11:27:49 +0100
It seems clang (or the “Apple LLVM Compiler”) doesn’t like it when I throw exceptions from a C++ destructor. Is this intentional, or should I report it as a bug?
(I aware that in general, throwing from a destructor is a very bad idea, I’m only doing it in very specific cases. For example, I know that my destructor is not called during stack unwinding due to another exception.)
For example, the following program will terminate with a “terminate called without an active exception” message when the destructor throws std::exception (testing using Xcode 4.5.2 on Mac OS X 10.7.5):
#include <stdexcept>
class CThrowInDestructor {
public: CThrowInDestructor() {}
public: ~CThrowInDestructor() {
throw std::exception();
}
};
int main(int argc, const char * argv[]) {
CThrowInDestructor* instance = new CThrowInDestructor;
try {
delete instance;
instance = NULL;
}
catch (...) {
}
return 0;
}
If I switch compiler to LLVM GCC 4.2, the program exits normally, so it seems the problem is specific to clang.
Thanks!
/Jesper
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden