serialization: remove incorrect noexcept on comparison operators [1/2]
QJsonValue comparison cannot be noexcept, because it might allocate, for example when calling QCborValue::toString(). As a result, all the QJsonValue(Const)Ref comparison operators also cannot be noexcept, because they convert to QJsonValue to do the comparison. QJsonObject comparison cannot be noexcept, because it might call QCborValue::makeValue(), which might allocate. QJsonArray comparison cannot be noexcept, because it might also call QCborValue::makeValue(), which might allocate. Found in 6.8 API review. Change-Id: I775746b2a76765bca26b87d5af396a8dfdfca7f9 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 7f01b62969d1734832ead0547904902ae0f1b5dd) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
67ce24cf30
commit
f2bcf582dd
@ -475,7 +475,7 @@ QJsonValue QJsonArray::operator[](qsizetype i) const
|
|||||||
return at(i);
|
return at(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool comparesEqual(const QJsonArray &lhs, const QJsonArray &rhs) noexcept
|
bool comparesEqual(const QJsonArray &lhs, const QJsonArray &rhs)
|
||||||
{
|
{
|
||||||
if (lhs.a == rhs.a)
|
if (lhs.a == rhs.a)
|
||||||
return true;
|
return true;
|
||||||
@ -494,7 +494,7 @@ bool comparesEqual(const QJsonArray &lhs, const QJsonArray &rhs) noexcept
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool comparesEqual(const QJsonArray &lhs, const QJsonValue &rhs) noexcept
|
bool comparesEqual(const QJsonArray &lhs, const QJsonValue &rhs)
|
||||||
{
|
{
|
||||||
return lhs == rhs.toArray();
|
return lhs == rhs.toArray();
|
||||||
}
|
}
|
||||||
|
@ -302,12 +302,12 @@ private:
|
|||||||
friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonArray &);
|
friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonArray &);
|
||||||
|
|
||||||
friend Q_CORE_EXPORT bool comparesEqual(const QJsonArray &lhs,
|
friend Q_CORE_EXPORT bool comparesEqual(const QJsonArray &lhs,
|
||||||
const QJsonArray &rhs) noexcept;
|
const QJsonArray &rhs);
|
||||||
|
|
||||||
friend Q_CORE_EXPORT bool comparesEqual(const QJsonArray &lhs,
|
friend Q_CORE_EXPORT bool comparesEqual(const QJsonArray &lhs,
|
||||||
const QJsonValue &rhs) noexcept;
|
const QJsonValue &rhs);
|
||||||
Q_DECLARE_EQUALITY_COMPARABLE(QJsonArray)
|
Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QJsonArray)
|
||||||
Q_DECLARE_EQUALITY_COMPARABLE(QJsonArray, QJsonValue)
|
Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QJsonArray, QJsonValue)
|
||||||
|
|
||||||
QJsonArray(QCborContainerPrivate *array);
|
QJsonArray(QCborContainerPrivate *array);
|
||||||
bool detach(qsizetype reserve = 0);
|
bool detach(qsizetype reserve = 0);
|
||||||
|
@ -621,7 +621,7 @@ bool QJsonObject::containsImpl(T key) const
|
|||||||
|
|
||||||
Returns \c true if \a lhs object is equal to \a rhs, \c false otherwise.
|
Returns \c true if \a lhs object is equal to \a rhs, \c false otherwise.
|
||||||
*/
|
*/
|
||||||
bool comparesEqual(const QJsonObject &lhs, const QJsonObject &rhs) noexcept
|
bool comparesEqual(const QJsonObject &lhs, const QJsonObject &rhs)
|
||||||
{
|
{
|
||||||
if (lhs.o == rhs.o)
|
if (lhs.o == rhs.o)
|
||||||
return true;
|
return true;
|
||||||
|
@ -313,20 +313,18 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
friend Q_CORE_EXPORT bool comparesEqual(const QJsonObject &lhs,
|
friend Q_CORE_EXPORT bool comparesEqual(const QJsonObject &lhs,
|
||||||
const QJsonObject &rhs) noexcept;
|
const QJsonObject &rhs);
|
||||||
friend bool comparesEqual(const QJsonObject &lhs,
|
friend bool comparesEqual(const QJsonObject &lhs, const QJsonValue &rhs)
|
||||||
const QJsonValue &rhs) noexcept
|
|
||||||
{
|
{
|
||||||
return comparesEqual(lhs, rhs.toObject());
|
return comparesEqual(lhs, rhs.toObject());
|
||||||
}
|
}
|
||||||
friend bool comparesEqual(const QJsonObject &lhs,
|
friend bool comparesEqual(const QJsonObject &lhs, const QJsonValueConstRef &rhs)
|
||||||
const QJsonValueConstRef &rhs) noexcept
|
|
||||||
{
|
{
|
||||||
return comparesEqual(lhs, rhs.toObject());
|
return comparesEqual(lhs, rhs.toObject());
|
||||||
}
|
}
|
||||||
Q_DECLARE_EQUALITY_COMPARABLE(QJsonObject)
|
Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QJsonObject)
|
||||||
Q_DECLARE_EQUALITY_COMPARABLE(QJsonObject, QJsonValue)
|
Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QJsonObject, QJsonValue)
|
||||||
Q_DECLARE_EQUALITY_COMPARABLE(QJsonObject, QJsonValueConstRef)
|
Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QJsonObject, QJsonValueConstRef)
|
||||||
friend class QJsonValue;
|
friend class QJsonValue;
|
||||||
friend class QJsonDocument;
|
friend class QJsonDocument;
|
||||||
friend class QJsonPrivate::Value;
|
friend class QJsonPrivate::Value;
|
||||||
|
@ -831,7 +831,7 @@ const QJsonValue QJsonValue::operator[](qsizetype i) const
|
|||||||
|
|
||||||
Returns \c true if the \a lhs value is equal to \a rhs value, \c false otherwise.
|
Returns \c true if the \a lhs value is equal to \a rhs value, \c false otherwise.
|
||||||
*/
|
*/
|
||||||
bool comparesEqual(const QJsonValue &lhs, const QJsonValue &rhs) noexcept
|
bool comparesEqual(const QJsonValue &lhs, const QJsonValue &rhs)
|
||||||
{
|
{
|
||||||
if (lhs.value.type() != rhs.value.type()) {
|
if (lhs.value.type() != rhs.value.type()) {
|
||||||
if (lhs.isDouble() && rhs.isDouble()) {
|
if (lhs.isDouble() && rhs.isDouble()) {
|
||||||
|
@ -100,8 +100,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
friend Q_CORE_EXPORT bool comparesEqual(const QJsonValue &lhs,
|
friend Q_CORE_EXPORT bool comparesEqual(const QJsonValue &lhs,
|
||||||
const QJsonValue &rhs) noexcept;
|
const QJsonValue &rhs);
|
||||||
Q_DECLARE_EQUALITY_COMPARABLE(QJsonValue)
|
Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QJsonValue)
|
||||||
|
|
||||||
// avoid implicit conversions from char * to bool
|
// avoid implicit conversions from char * to bool
|
||||||
QJsonValue(const void *) = delete;
|
QJsonValue(const void *) = delete;
|
||||||
@ -157,17 +157,17 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend bool comparesEqual(const QJsonValueConstRef &lhs,
|
friend bool comparesEqual(const QJsonValueConstRef &lhs,
|
||||||
const QJsonValueConstRef &rhs) noexcept
|
const QJsonValueConstRef &rhs)
|
||||||
{
|
{
|
||||||
return comparesEqual(concrete(lhs), concrete(rhs));
|
return comparesEqual(concrete(lhs), concrete(rhs));
|
||||||
}
|
}
|
||||||
friend bool comparesEqual(const QJsonValueConstRef &lhs,
|
friend bool comparesEqual(const QJsonValueConstRef &lhs,
|
||||||
const QJsonValue &rhs) noexcept
|
const QJsonValue &rhs)
|
||||||
{
|
{
|
||||||
return comparesEqual(concrete(lhs), rhs);
|
return comparesEqual(concrete(lhs), rhs);
|
||||||
}
|
}
|
||||||
Q_DECLARE_EQUALITY_COMPARABLE(QJsonValueConstRef)
|
Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QJsonValueConstRef)
|
||||||
Q_DECLARE_EQUALITY_COMPARABLE(QJsonValueConstRef, QJsonValue)
|
Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QJsonValueConstRef, QJsonValue)
|
||||||
|
|
||||||
Q_CORE_EXPORT static QJsonValue::Type
|
Q_CORE_EXPORT static QJsonValue::Type
|
||||||
concreteType(QJsonValueConstRef self) noexcept Q_DECL_PURE_FUNCTION;
|
concreteType(QJsonValueConstRef self) noexcept Q_DECL_PURE_FUNCTION;
|
||||||
@ -280,18 +280,16 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend bool comparesEqual(const QJsonValueRef &lhs,
|
friend bool comparesEqual(const QJsonValueRef &lhs, const QJsonValueRef &rhs)
|
||||||
const QJsonValueRef &rhs) noexcept
|
|
||||||
{
|
{
|
||||||
return comparesEqual(QJsonValue(lhs), QJsonValue(rhs));
|
return comparesEqual(QJsonValue(lhs), QJsonValue(rhs));
|
||||||
}
|
}
|
||||||
friend bool comparesEqual(const QJsonValueRef &lhs,
|
friend bool comparesEqual(const QJsonValueRef &lhs, const QJsonValueConstRef &rhs)
|
||||||
const QJsonValueConstRef &rhs) noexcept
|
|
||||||
{
|
{
|
||||||
return comparesEqual(QJsonValue(lhs), QJsonValue(rhs));
|
return comparesEqual(QJsonValue(lhs), QJsonValue(rhs));
|
||||||
}
|
}
|
||||||
Q_DECLARE_EQUALITY_COMPARABLE(QJsonValueRef)
|
Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QJsonValueRef)
|
||||||
Q_DECLARE_EQUALITY_COMPARABLE(QJsonValueRef, QJsonValueConstRef)
|
Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QJsonValueRef, QJsonValueConstRef)
|
||||||
|
|
||||||
QJsonValue toValue() const;
|
QJsonValue toValue() const;
|
||||||
#else
|
#else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user