Call std::addressof instead of operator& in QDebug::toString
QDebug::toString intends to pass the input object's address to its nested implementation, but was calling operator& which does not work with types that has a custom overload. Calling std::addressof fixes this problem. Fixes: QTBUG-127510 Pick-to: 6.8 Change-Id: Ie608f7b1a63c4032246b6ff98a3651695f0536ca Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
02cb165ef8
commit
6cd6c3d6d7
@ -22,6 +22,7 @@
|
||||
#include <chrono>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
@ -241,7 +242,7 @@ public:
|
||||
template <typename T>
|
||||
static QString toString(const T &object)
|
||||
{
|
||||
return toStringImpl(&streamTypeErased<T>, &object);
|
||||
return toStringImpl(&streamTypeErased<T>, std::addressof(object));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -1343,6 +1343,19 @@ void tst_QDebug::toString() const
|
||||
stream.nospace() << &qobject;
|
||||
QCOMPARE(QDebug::toString(&qobject), expectedString);
|
||||
}
|
||||
|
||||
// Overloaded operator&
|
||||
{
|
||||
struct TypeWithAddressOf
|
||||
{
|
||||
int* operator&() const { return nullptr; }
|
||||
operator QByteArray() const { return "test"; }
|
||||
};
|
||||
|
||||
TypeWithAddressOf object;
|
||||
QString expectedString {"\"test\""};
|
||||
QCOMPARE(QDebug::toString(object), expectedString);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDebug::noQVariantEndlessRecursion() const
|
||||
|
Loading…
x
Reference in New Issue
Block a user