From 91a27c1a516068b69ab62778a07c566ad22f3576 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 7 Aug 2024 15:28:51 -0700 Subject: QDebug: cast the QFlags value to the right-sized unsigned type (1/2) This change fixes three problems in the non-Q_ENUM overload. First, the printing of the sign bit for a signed flag. This is correct, but unexpected: QFlags(0x1|0x2|-0x80000000) By using unsigned types, we'll print instead: QFlags(0x1|0x2|0x80000000) Second, shifting into the sign bit is UB, so we remove the problem by not having a sign bit at all. Third, this provides an out-of-line non-template overload of the implementation for unsigned QFlags, thereby avoiding an unnecessary instantiation of the template function qt_QMetaEnum_flagDebugOperator() in user code. Pick-to: 6.8 Change-Id: I8a96935cf6c742259c9dfffd17e992caa315e1d3 Reviewed-by: Ahmad Samir Reviewed-by: Fabian Kosmale --- src/corelib/io/qdebug.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/corelib/io/qdebug.cpp') diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 42515be1187..d5bdfadba92 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -1323,13 +1323,13 @@ QDebugStateSaver::~QDebugStateSaver() \internal Specialization of the primary template in qdebug.h to out-of-line - the common case of QFlags::Int being int. + the common case of QFlags::Int being 32-bit. Just call the generic version so the two don't get out of sync. */ -void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, int value) +void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, uint value) { - qt_QMetaEnum_flagDebugOperator(debug, sizeofT, value); + qt_QMetaEnum_flagDebugOperator(debug, sizeofT, value); } #ifndef QT_NO_QOBJECT -- cgit v1.2.3