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 <thiago.macieira@intel.com>
bb10
Marc Mutz 2022-02-18 17:19:19 +01:00
parent 29b18a0179
commit ef6c4dfb1c
2 changed files with 10 additions and 5 deletions

View File

@ -60,6 +60,11 @@
QT_BEGIN_NAMESPACE
static_assert(std::is_nothrow_move_constructible_v<QStringEncoder>);
static_assert(std::is_nothrow_move_assignable_v<QStringEncoder>);
static_assert(std::is_nothrow_move_constructible_v<QStringDecoder>);
static_assert(std::is_nothrow_move_assignable_v<QStringDecoder>);
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);

View File

@ -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)