Details
-
Bug
-
Resolution: Duplicate
-
P4: Low
-
None
-
4.8.x, 5.5.1, 5.6.0
-
None
Description
QSharedPointer<T>::create(...) can be used as the Qt equivalent of std::make_shared<T>(...). These functions call T's constructor automatically for the user.
When the constructor throws an exception, the compiler will itself ensure to leave the object in a destructed state so that QSharedPointer<T>::create(...) should not manually call T::~T when the construction failed by an exception. However, that's what it does and it's highly likely to crash or misbehave in other ways for every non-trivial real-world situation.
class X { public: X() { throw 42; } ~X() { std::cout << "~X called!"; } }; int main() { try { QSharedPointer<X>::create(); } catch(...) { std::cout << "catched!"; } }
Expected output: "catched!". Actual output: "~X called!catched".
Attachments
Issue Links
- is replaced by
-
QTBUG-49824 QSharedPointer::create calls destructor when an exception is thrown
-
- Closed
-