Improve casting

Make a handful of narrowing casts explicit

Change-Id: I318e9778840f2437963377b6b97f269d569909dc
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
This commit is contained in:
Allan Sandfeld Jensen 2020-05-11 10:26:50 +02:00
parent e721ec269e
commit a418fd5cbb
5 changed files with 9 additions and 9 deletions

View File

@ -72,7 +72,7 @@ class qfloat16
// To let our private constructor work, without other code seeing // To let our private constructor work, without other code seeing
// ambiguity when constructing from int, double &c. // ambiguity when constructing from int, double &c.
quint16 b16; quint16 b16;
constexpr inline explicit Wrap(int value) : b16(value) {} constexpr inline explicit Wrap(int value) : b16(quint16(value)) {}
}; };
public: public:
constexpr inline qfloat16() noexcept : b16(0) {} constexpr inline qfloat16() noexcept : b16(0) {}
@ -172,8 +172,8 @@ inline qfloat16::qfloat16(float f) noexcept
#else #else
quint32 u; quint32 u;
memcpy(&u, &f, sizeof(quint32)); memcpy(&u, &f, sizeof(quint32));
b16 = basetable[(u >> 23) & 0x1ff] b16 = quint16(basetable[(u >> 23) & 0x1ff]
+ ((u & 0x007fffff) >> shifttable[(u >> 23) & 0x1ff]); + ((u & 0x007fffff) >> shifttable[(u >> 23) & 0x1ff]));
#endif #endif
} }
QT_WARNING_POP QT_WARNING_POP
@ -268,8 +268,8 @@ QF16_MAKE_BOOL_OP(float)
#undef QF16_MAKE_BOOL_OP_FP #undef QF16_MAKE_BOOL_OP_FP
#define QF16_MAKE_BOOL_OP_INT(OP) \ #define QF16_MAKE_BOOL_OP_INT(OP) \
inline bool operator OP(qfloat16 a, int b) noexcept { return static_cast<float>(a) OP b; } \ inline bool operator OP(qfloat16 a, int b) noexcept { return static_cast<float>(a) OP static_cast<float>(b); } \
inline bool operator OP(int a, qfloat16 b) noexcept { return a OP static_cast<float>(b); } inline bool operator OP(int a, qfloat16 b) noexcept { return static_cast<float>(a) OP static_cast<float>(b); }
QF16_MAKE_BOOL_OP_INT(>) QF16_MAKE_BOOL_OP_INT(>)
QF16_MAKE_BOOL_OP_INT(<) QF16_MAKE_BOOL_OP_INT(<)
QF16_MAKE_BOOL_OP_INT(>=) QF16_MAKE_BOOL_OP_INT(>=)

View File

@ -101,7 +101,7 @@ private:
static Q_DECL_RELAXED_CONSTEXPR Skiptable generate(const char *pattern, uint n) noexcept static Q_DECL_RELAXED_CONSTEXPR Skiptable generate(const char *pattern, uint n) noexcept
{ {
const auto uchar_max = (std::numeric_limits<uchar>::max)(); const auto uchar_max = (std::numeric_limits<uchar>::max)();
uchar max = n > uchar_max ? uchar_max : n; uchar max = n > uchar_max ? uchar_max : uchar(n);
Skiptable table = { Skiptable table = {
// this verbose initialization code aims to avoid some opaque error messages // this verbose initialization code aims to avoid some opaque error messages
// even on powerful compilers such as GCC 5.3. Even though for GCC a loop // even on powerful compilers such as GCC 5.3. Even though for GCC a loop

View File

@ -90,7 +90,7 @@ public:
inline int index() const inline int index() const
{ {
return pos - i; return int(pos - i);
} }
inline void setPosition(QString::const_iterator position) inline void setPosition(QString::const_iterator position)

View File

@ -77,7 +77,7 @@ Q_DECL_CONSTEXPR inline int fromHex(uint c) noexcept
Q_DECL_CONSTEXPR inline char toOct(uint value) noexcept Q_DECL_CONSTEXPR inline char toOct(uint value) noexcept
{ {
return '0' + char(value & 0x7); return char('0' + (value & 0x7));
} }
Q_DECL_CONSTEXPR inline int fromOct(uint c) noexcept Q_DECL_CONSTEXPR inline int fromOct(uint c) noexcept

View File

@ -157,7 +157,7 @@ class QVersionNumber
{ return isUsingPointer() ? pointer_segments->size() : (inline_segments[InlineSegmentMarker] >> 1); } { return isUsingPointer() ? pointer_segments->size() : (inline_segments[InlineSegmentMarker] >> 1); }
void setInlineSize(int len) void setInlineSize(int len)
{ inline_segments[InlineSegmentMarker] = 1 + 2 * len; } { inline_segments[InlineSegmentMarker] = qint8(1 + 2 * len); }
void resize(int len) void resize(int len)
{ {