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 <thiago.macieira@intel.com>
This commit is contained in:
Ahmad Samir 2023-03-08 13:18:58 +02:00
parent d4dba80863
commit fd48bcec52
2 changed files with 4 additions and 5 deletions

View File

@ -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<int>(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<int>(value));
if (enumScope)
debug << ')';

View File

@ -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<int>(ll));
if (toType.id() == QMetaType::QString)
*static_cast<QString *>(to) = QString::fromUtf8(keys);
else
*static_cast<QByteArray *>(to) = keys;
} else {
const char *key = en.valueToKey(ll);
const char *key = en.valueToKey(static_cast<int>(ll));
if (toType.id() == QMetaType::QString)
*static_cast<QString *>(to) = QString::fromUtf8(key);
else