From fd48bcec525eb8322c8e1c81307cc9254f608062 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Wed, 8 Mar 2023 13:18:58 +0200 Subject: [PATCH] QMetaEnum: fix narrowing warnings related to valueToKey*() valueToKey*() takes an int, and QMetaEnum internally assumes the underlying type of an enum is not bigger than int. Using static_cast as it's easier to search for it in the codebase if needed. Found by compiling with -Wshorten-64-to-32. Drive-by change: remove qdoc \fn command for qt_QMetaEnum_debugOperator, it's an internal method and defined right under the doc block (the signature still said "int" but it's qint64). Change-Id: Ia6abc85173bf94c0a8c56663481d83d3a998f68d Reviewed-by: Thiago Macieira --- src/corelib/io/qdebug.cpp | 5 ++--- src/corelib/kernel/qmetatype.cpp | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index baef75b234..16bb140228 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -1028,7 +1028,6 @@ void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, int value) #ifndef QT_NO_QOBJECT /*! - \fn QDebug qt_QMetaEnum_debugOperator(QDebug &, int value, const QMetaObject *, const char *name) \internal Formats the given enum \a value for debug output. @@ -1075,7 +1074,7 @@ QDebug qt_QMetaEnum_debugOperator(QDebug &dbg, qint64 value, const QMetaObject * dbg << scope << u"::"; } - const char *key = me.valueToKey(value); + const char *key = me.valueToKey(static_cast(value)); const bool scoped = me.isScoped() || verbosity & 1; if (scoped || !key) dbg << me.enumName() << (!key ? u"(" : u"::"); @@ -1144,7 +1143,7 @@ QDebug qt_QMetaEnum_flagDebugOperator(QDebug &debug, quint64 value, const QMetaO debug << '('; } - debug << me.valueToKeys(value); + debug << me.valueToKeys(static_cast(value)); if (enumScope) debug << ')'; diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 139c4ec776..4006b348e1 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -1951,13 +1951,13 @@ static bool convertFromEnum(QMetaType fromType, const void *from, QMetaType toTy QMetaEnum en = metaEnumFromType(fromType); if (en.isValid()) { if (en.isFlag()) { - const QByteArray keys = en.valueToKeys(ll); + const QByteArray keys = en.valueToKeys(static_cast(ll)); if (toType.id() == QMetaType::QString) *static_cast(to) = QString::fromUtf8(keys); else *static_cast(to) = keys; } else { - const char *key = en.valueToKey(ll); + const char *key = en.valueToKey(static_cast(ll)); if (toType.id() == QMetaType::QString) *static_cast(to) = QString::fromUtf8(key); else