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 Change-Id: Ie608f7b1a63c4032246b6ff98a3651695f0536ca Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 6cd6c3d6d70f8e76059153dd58ed2c61af2889b3) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
633013827a
commit
b64e918c85
@ -21,6 +21,7 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
@ -235,7 +236,7 @@ public:
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
static QString toString(const T &object)
|
static QString toString(const T &object)
|
||||||
{
|
{
|
||||||
return toStringImpl(&streamTypeErased<T>, &object);
|
return toStringImpl(&streamTypeErased<T>, std::addressof(object));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1343,6 +1343,19 @@ void tst_QDebug::toString() const
|
|||||||
stream.nospace() << &qobject;
|
stream.nospace() << &qobject;
|
||||||
QCOMPARE(QDebug::toString(&qobject), expectedString);
|
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
|
void tst_QDebug::noQVariantEndlessRecursion() const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user