From 5e75ef6d8bb64303cdf4d3cc37cc1b59fd554f8f Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 7 Jan 2025 11:08:30 +0100 Subject: [PATCH] QException: honor the RO5 QException has an out-of-line destructor in order to pin its vtable. But like any std::exception subclass it's meant to be (and effectively is) copy-constructible and copy-assignable (cf. [exception]/2). Add the missing copy operations, and the default constructor. One may argue that this class should use some other approach since it also has a polymorphic clone() -- for instance disable assignments and make copy constructions protected -- but that ship has sailed. This prevents a Clang warning about the deprecated copies in the presence of a user-declared destructor. Change-Id: I4d8613ade265ea85a5a7e97255b75b7fcf3e5a27 Reviewed-by: Thiago Macieira (cherry picked from commit 793309693aac24e7f88fc225408d92def638996e) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit 37a553a3a51cfe58b73083432634ba4235401b10) --- src/corelib/thread/qexception.cpp | 27 +++++++++++++++++++++++++++ src/corelib/thread/qexception.h | 3 +++ 2 files changed, 30 insertions(+) diff --git a/src/corelib/thread/qexception.cpp b/src/corelib/thread/qexception.cpp index fd98505282e..9e3d148491e 100644 --- a/src/corelib/thread/qexception.cpp +++ b/src/corelib/thread/qexception.cpp @@ -82,10 +82,37 @@ QT_BEGIN_NAMESPACE \internal */ +/*! + Destroys this QException object. +*/ QException::~QException() noexcept { } +/*! + \fn QException::QException() + + Constructs a QException object. +*/ + +/*! + \fn QException::QException(const QException &other) + + Creates a copy of \a other. + + \note Be careful when using this function, as you risk slicing. + + \sa clone() +*/ + +/*! + \fn QException &QException::operator=(const QException &other) + + Copy-assigns \a other over this object. + + \note Be careful when using this function, as you risk slicing. +*/ + void QException::raise() const { QException e = *this; diff --git a/src/corelib/thread/qexception.h b/src/corelib/thread/qexception.h index 62b9e70bea4..e5c62873509 100644 --- a/src/corelib/thread/qexception.h +++ b/src/corelib/thread/qexception.h @@ -21,7 +21,10 @@ QT_BEGIN_NAMESPACE class Q_CORE_EXPORT QException : public std::exception { public: + QException() = default; ~QException() noexcept; + QException(const QException &) = default; + QException &operator=(const QException &) = default; virtual void raise() const; virtual QException *clone() const; };