From ef6c4dfb1c14a55e480cc2c92555da4c93f01daf Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 18 Feb 2022 17:19:19 +0100 Subject: [PATCH] QStringConverter/Encoder/Decoder: make move noexcept The State state data member had non-noexcept move-SMFs, which were inherited by the move-SMFs of QStringConverter, QStringEncoder and QStringDecoder. To fix, because it is called in the move-assignment operator, we need to mark State::clear() as noexcept, and, since that can perform an indirect call through clearFn, require the clearFn to be noexcept, too. The only users of clearFn were in Qt5Compat; a separate fix should have been merged there by the time this lands. Change-Id: Ibe8147970886526b6a479960050e108607b63874 Reviewed-by: Thiago Macieira --- src/corelib/text/qstringconverter.cpp | 7 ++++++- src/corelib/text/qstringconverter_base.h | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/corelib/text/qstringconverter.cpp b/src/corelib/text/qstringconverter.cpp index e6c2552348..199e85aaae 100644 --- a/src/corelib/text/qstringconverter.cpp +++ b/src/corelib/text/qstringconverter.cpp @@ -60,6 +60,11 @@ QT_BEGIN_NAMESPACE +static_assert(std::is_nothrow_move_constructible_v); +static_assert(std::is_nothrow_move_assignable_v); +static_assert(std::is_nothrow_move_constructible_v); +static_assert(std::is_nothrow_move_assignable_v); + enum { Endian = 0, Data = 1 }; static const uchar utf8bom[] = { 0xef, 0xbb, 0xbf }; @@ -1388,7 +1393,7 @@ QByteArray QLocal8Bit::convertFromUnicode(QStringView in, QStringConverter::Stat } #endif -void QStringConverter::State::clear() +void QStringConverter::State::clear() noexcept { if (clearFn) clearFn(this); diff --git a/src/corelib/text/qstringconverter_base.h b/src/corelib/text/qstringconverter_base.h index ac147892ee..f726d95b82 100644 --- a/src/corelib/text/qstringconverter_base.h +++ b/src/corelib/text/qstringconverter_base.h @@ -73,14 +73,14 @@ public: constexpr State(Flags f = Flag::Default) : flags(f), state_data{0, 0, 0, 0} {} ~State() { clear(); } - State(State &&other) + State(State &&other) noexcept : flags(other.flags), remainingChars(other.remainingChars), invalidChars(other.invalidChars), d{other.d[0], other.d[1]}, clearFn(other.clearFn) { other.clearFn = nullptr; } - State &operator=(State &&other) + State &operator=(State &&other) noexcept { clear(); flags = other.flags; @@ -92,7 +92,7 @@ public: other.clearFn = nullptr; return *this; } - Q_CORE_EXPORT void clear(); + Q_CORE_EXPORT void clear() noexcept; Flags flags; int internalState = 0; @@ -103,7 +103,7 @@ public: uint state_data[4]; void *d[2]; }; - using ClearDataFn = void (*)(State *); + using ClearDataFn = void (*)(State *) noexcept; ClearDataFn clearFn = nullptr; private: Q_DISABLE_COPY(State)