diff options
author | David Faure <faure@kde.org> | 2009-09-13 08:18:57 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-09-13 08:18:57 (GMT) |
commit | b2f2967411bcb23a807f6a17b042b4c58701af95 (patch) | |
tree | 7db490cf7846973e8b9850a87a0abd0e54944c0c /src | |
parent | 139cffbfe1598b32ffe658968694d163dc53e3dd (diff) | |
download | Qt-b2f2967411bcb23a807f6a17b042b4c58701af95.zip Qt-b2f2967411bcb23a807f6a17b042b4c58701af95.tar.gz Qt-b2f2967411bcb23a807f6a17b042b4c58701af95.tar.bz2 |
Fix -Wconversion warnings where possible.
In order to detect "int foo = myQReal" mistakes, one needs to compile with -Wconversion.
However that flag triggers many warnings inside Qt. This commit fixes many of them, like
qchar.h:295: warning: conversion to 'ushort' from 'unsigned int' may alter its value
qglobal.h:1026: warning: conversion to 'qreal' from 'qint64' may alter its value
qbytearray.h:441: warning: conversion to 'char' from 'int' may alter its value
Other warnings remain (such as those coming from bitfields)
Merge-request: 1460
Reviewed-by: Thiago Macieira <thiago.macieira@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/global/qendian.h | 18 | ||||
-rw-r--r-- | src/corelib/global/qglobal.h | 4 | ||||
-rw-r--r-- | src/corelib/io/qiodevice.h | 2 | ||||
-rw-r--r-- | src/corelib/kernel/qmath.h | 16 | ||||
-rw-r--r-- | src/corelib/tools/qalgorithms.h | 14 | ||||
-rw-r--r-- | src/corelib/tools/qbitarray.h | 8 | ||||
-rw-r--r-- | src/corelib/tools/qbytearray.h | 4 | ||||
-rw-r--r-- | src/corelib/tools/qchar.h | 10 | ||||
-rw-r--r-- | src/corelib/tools/qlist.h | 8 | ||||
-rw-r--r-- | src/corelib/tools/qvector.h | 6 | ||||
-rw-r--r-- | src/gui/kernel/qsizepolicy.h | 4 |
11 files changed, 47 insertions, 47 deletions
diff --git a/src/corelib/global/qendian.h b/src/corelib/global/qendian.h index 3c804ce..5d9141f 100644 --- a/src/corelib/global/qendian.h +++ b/src/corelib/global/qendian.h @@ -149,9 +149,9 @@ template <> inline quint32 qFromLittleEndian<quint32>(const uchar *src) template <> inline quint16 qFromLittleEndian<quint16>(const uchar *src) { - return 0 - | src[0] - | src[1] * 0x0100; + return quint16(0 + | src[0] + | src[1] * 0x0100); } // signed specializations @@ -241,9 +241,9 @@ inline quint32 qFromBigEndian<quint32>(const uchar *src) template<> inline quint16 qFromBigEndian<quint16>(const uchar *src) { - return 0 - | src[1] - | src[0] * quint16(0x0100); + return quint16( 0 + | src[1] + | src[0] * quint16(0x0100)); } @@ -288,9 +288,9 @@ template <> inline quint32 qbswap<quint32>(quint32 source) template <> inline quint16 qbswap<quint16>(quint16 source) { - return 0 - | ((source & 0x00ff) << 8) - | ((source & 0xff00) >> 8); + return quint16( 0 + | ((source & 0x00ff) << 8) + | ((source & 0xff00) >> 8) ); } // signed specializations diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index b97b9d1..897dcea 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1081,10 +1081,10 @@ inline int qRound(qreal d) #if defined(QT_NO_FPU) || defined(QT_ARCH_ARM) || defined(QT_ARCH_WINDOWSCE) || defined(QT_ARCH_SYMBIAN) inline qint64 qRound64(double d) -{ return d >= 0.0 ? qint64(d + 0.5) : qint64(d - qint64(d-1) + 0.5) + qint64(d-1); } +{ return d >= 0.0 ? qint64(d + 0.5) : qint64(d - qreal(qint64(d-1)) + 0.5) + qint64(d-1); } #else inline qint64 qRound64(qreal d) -{ return d >= 0.0 ? qint64(d + 0.5) : qint64(d - qint64(d-1) + 0.5) + qint64(d-1); } +{ return d >= 0.0 ? qint64(d + 0.5) : qint64(d - qreal(qint64(d-1)) + 0.5) + qint64(d-1); } #endif template <typename T> diff --git a/src/corelib/io/qiodevice.h b/src/corelib/io/qiodevice.h index adb8f1c..60ca74c 100644 --- a/src/corelib/io/qiodevice.h +++ b/src/corelib/io/qiodevice.h @@ -198,7 +198,7 @@ public: inline QT3_SUPPORT qint64 writeBlock(const QByteArray &data) { return write(data); } inline QT3_SUPPORT int getch() { char c; return getChar(&c) ? int(uchar(c)) : -1; } - inline QT3_SUPPORT int putch(int c) { return putChar(c) ? int(uchar(c)) : -1; } + inline QT3_SUPPORT int putch(int c) { return putChar(char(c)) ? int(uchar(c)) : -1; } inline QT3_SUPPORT int ungetch(int c) { ungetChar(uchar(c)); return c; } #endif }; diff --git a/src/corelib/kernel/qmath.h b/src/corelib/kernel/qmath.h index bc0f46f..b521323 100644 --- a/src/corelib/kernel/qmath.h +++ b/src/corelib/kernel/qmath.h @@ -56,7 +56,7 @@ inline int qCeil(qreal v) { #ifdef QT_USE_MATH_H_FLOATS if (sizeof(qreal) == sizeof(float)) - return int(ceilf(v)); + return int(ceilf(float(v))); else #endif return int(ceil(v)); @@ -66,7 +66,7 @@ inline int qFloor(qreal v) { #ifdef QT_USE_MATH_H_FLOATS if (sizeof(qreal) == sizeof(float)) - return int(floorf(v)); + return int(floorf(float(v))); else #endif return int(floor(v)); @@ -76,7 +76,7 @@ inline qreal qSin(qreal v) { #ifdef QT_USE_MATH_H_FLOATS if (sizeof(qreal) == sizeof(float)) - return sinf(v); + return sinf(float(v)); else #endif return sin(v); @@ -86,7 +86,7 @@ inline qreal qCos(qreal v) { #ifdef QT_USE_MATH_H_FLOATS if (sizeof(qreal) == sizeof(float)) - return cosf(v); + return cosf(float(v)); else #endif return cos(v); @@ -96,7 +96,7 @@ inline qreal qAcos(qreal v) { #ifdef QT_USE_MATH_H_FLOATS if (sizeof(qreal) == sizeof(float)) - return acosf(v); + return acosf(float(v)); else #endif return acos(v); @@ -106,7 +106,7 @@ inline qreal qSqrt(qreal v) { #ifdef QT_USE_MATH_H_FLOATS if (sizeof(qreal) == sizeof(float)) - return sqrtf(v); + return sqrtf(float(v)); else #endif return sqrt(v); @@ -116,7 +116,7 @@ inline qreal qLn(qreal v) { #ifdef QT_USE_MATH_H_FLOATS if (sizeof(qreal) == sizeof(float)) - return logf(v); + return logf(float(v)); else #endif return log(v); @@ -126,7 +126,7 @@ inline qreal qPow(qreal x, qreal y) { #ifdef QT_USE_MATH_H_FLOATS if (sizeof(qreal) == sizeof(float)) - return powf(x, y); + return powf(float(x), float(y)); else #endif return pow(x, y); diff --git a/src/corelib/tools/qalgorithms.h b/src/corelib/tools/qalgorithms.h index 312cd4c..a68ce27 100644 --- a/src/corelib/tools/qalgorithms.h +++ b/src/corelib/tools/qalgorithms.h @@ -227,7 +227,7 @@ template <typename RandomAccessIterator, typename T> Q_OUTOFLINE_TEMPLATE RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value) { // Implementation is duplicated from QAlgorithmsPrivate to keep existing code - // compiling. We have to allow using *begin and value with different types, + // compiling. We have to allow using *begin and value with different types, // and then implementing operator< for those types. RandomAccessIterator middle; int n = end - begin; @@ -351,7 +351,7 @@ template <typename RandomAccessIterator, typename T, typename LessThan> Q_OUTOFLINE_TEMPLATE void qSortHelper(RandomAccessIterator start, RandomAccessIterator end, const T &t, LessThan lessThan) { top: - int span = end - start; + int span = int(end - start); if (span < 2) return; @@ -417,9 +417,9 @@ Q_OUTOFLINE_TEMPLATE void qReverse(RandomAccessIterator begin, RandomAccessItera template <typename RandomAccessIterator> Q_OUTOFLINE_TEMPLATE void qRotate(RandomAccessIterator begin, RandomAccessIterator middle, RandomAccessIterator end) { - qReverse(begin, middle); - qReverse(middle, end); - qReverse(begin, end); + qReverse(begin, middle); + qReverse(middle, end); + qReverse(begin, end); } template <typename RandomAccessIterator, typename T, typename LessThan> @@ -463,7 +463,7 @@ Q_OUTOFLINE_TEMPLATE void qStableSortHelper(RandomAccessIterator begin, RandomAc const int span = end - begin; if (span < 2) return; - + const RandomAccessIterator middle = begin + span / 2; qStableSortHelper(begin, middle, t, lessThan); qStableSortHelper(middle, end, t, lessThan); @@ -480,7 +480,7 @@ template <typename RandomAccessIterator, typename T, typename LessThan> Q_OUTOFLINE_TEMPLATE RandomAccessIterator qLowerBoundHelper(RandomAccessIterator begin, RandomAccessIterator end, const T &value, LessThan lessThan) { RandomAccessIterator middle; - int n = end - begin; + int n = int(end - begin); int half; while (n > 0) { diff --git a/src/corelib/tools/qbitarray.h b/src/corelib/tools/qbitarray.h index c922262..2ae77b7 100644 --- a/src/corelib/tools/qbitarray.h +++ b/src/corelib/tools/qbitarray.h @@ -121,19 +121,19 @@ inline bool QBitArray::testBit(int i) const inline void QBitArray::setBit(int i) { Q_ASSERT(i >= 0 && i < size()); - *(reinterpret_cast<uchar*>(d.data())+1+(i>>3)) |= (1 << (i & 7)); } + *(reinterpret_cast<uchar*>(d.data())+1+(i>>3)) |= uchar(1 << (i & 7)); } inline void QBitArray::clearBit(int i) { Q_ASSERT(i >= 0 && i < size()); - *(reinterpret_cast<uchar*>(d.data())+1+(i>>3)) &= ~(1 << (i & 7)); } + *(reinterpret_cast<uchar*>(d.data())+1+(i>>3)) &= ~uchar(1 << (i & 7)); } inline void QBitArray::setBit(int i, bool val) { if (val) setBit(i); else clearBit(i); } inline bool QBitArray::toggleBit(int i) { Q_ASSERT(i >= 0 && i < size()); - uchar b = 1<< (i&7); uchar* p = reinterpret_cast<uchar*>(d.data())+1+(i>>3); - uchar c = *p&b; *p^=b; return c!=0; } + uchar b = uchar(1<<(i&7)); uchar* p = reinterpret_cast<uchar*>(d.data())+1+(i>>3); + uchar c = uchar(*p&b); *p^=b; return c!=0; } inline bool QBitArray::operator[](int i) const { return testBit(i); } inline bool QBitArray::operator[](uint i) const { return testBit(i); } diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index 14425ba..e258481 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -442,10 +442,10 @@ class Q_CORE_EXPORT QByteRef { public: #ifdef Q_COMPILER_MANGLES_RETURN_TYPE inline operator const char() const - { return i < a.d->size ? a.d->data[i] : 0; } + { return i < a.d->size ? a.d->data[i] : char(0); } #else inline operator char() const - { return i < a.d->size ? a.d->data[i] : 0; } + { return i < a.d->size ? a.d->data[i] : char(0); } #endif inline QByteRef &operator=(char c) { if (i >= a.d->size) a.expand(i); else a.detach(); diff --git a/src/corelib/tools/qchar.h b/src/corelib/tools/qchar.h index bcfb361..5ece472 100644 --- a/src/corelib/tools/qchar.h +++ b/src/corelib/tools/qchar.h @@ -292,10 +292,10 @@ public: return (uint(high.ucs)<<10) + low.ucs - 0x35fdc00; } static inline ushort highSurrogate(uint ucs4) { - return (ucs4>>10) + 0xd7c0; + return ushort((ucs4>>10) + 0xd7c0); } static inline ushort lowSurrogate(uint ucs4) { - return ucs4%0x400 + 0xdc00; + return ushort(ucs4%0x400 + 0xdc00); } static Category QT_FASTCALL category(uint ucs4); @@ -366,7 +366,7 @@ inline char QChar::toLatin1() const { return ucs > 0xff ? '\0' : char(ucs); } #endif inline QChar QChar::fromLatin1(char c) { return QChar(ushort(uchar(c))); } -inline QChar::QChar(uchar c, uchar r) : ucs((r << 8) | c){} +inline QChar::QChar(uchar c, uchar r) : ucs(ushort((r << 8) | c)){} inline QChar::QChar(short rc) : ucs(ushort(rc)){} inline QChar::QChar(uint rc) : ucs(ushort(rc & 0xffff)){} inline QChar::QChar(int rc) : ucs(ushort(rc & 0xffff)){} @@ -374,9 +374,9 @@ inline QChar::QChar(SpecialCharacter s) : ucs(ushort(s)) {} inline QChar::QChar(QLatin1Char ch) : ucs(ch.unicode()) {} inline void QChar::setCell(uchar acell) -{ ucs = (ucs & 0xff00) + acell; } +{ ucs = ushort((ucs & 0xff00) + acell); } inline void QChar::setRow(uchar arow) -{ ucs = (ushort(arow)<<8) + (ucs&0xff); } +{ ucs = ushort((ushort(arow)<<8) + (ucs&0xff)); } inline bool operator==(QChar c1, QChar c2) { return c1.unicode() == c2.unicode(); } inline bool operator!=(QChar c1, QChar c2) { return c1.unicode() != c2.unicode(); } diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 3111426..49b5c0d 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -202,7 +202,7 @@ public: inline iterator &operator-=(int j) { i-=j; return *this; } inline iterator operator+(int j) const { return iterator(i+j); } inline iterator operator-(int j) const { return iterator(i-j); } - inline int operator-(iterator j) const { return i - j.i; } + inline int operator-(iterator j) const { return int(i - j.i); } }; friend class iterator; @@ -420,7 +420,7 @@ Q_INLINE_TEMPLATE QList<T> &QList<T>::operator=(const QList<T> &l) template <typename T> inline typename QList<T>::iterator QList<T>::insert(iterator before, const T &t) { - int iBefore = before.i - reinterpret_cast<Node *>(p.begin()); + int iBefore = int(before.i - reinterpret_cast<Node *>(p.begin())); Node *n = reinterpret_cast<Node *>(p.insert(iBefore)); QT_TRY { node_construct(n, t); @@ -706,7 +706,7 @@ Q_OUTOFLINE_TEMPLATE QList<T> &QList<T>::operator+=(const QList<T> &l) node_copy(n, reinterpret_cast<Node *>(p.end()), reinterpret_cast<Node *>(l.p.begin())); } QT_CATCH(...) { // restore the old end - d->end -= (reinterpret_cast<Node *>(p.end()) - n); + d->end -= int(reinterpret_cast<Node *>(p.end()) - n); QT_RETHROW; } return *this; @@ -728,7 +728,7 @@ Q_OUTOFLINE_TEMPLATE int QList<T>::indexOf(const T &t, int from) const Node *e = reinterpret_cast<Node *>(p.end()); while (++n != e) if (n->t() == t) - return n - reinterpret_cast<Node *>(p.begin()); + return int(n - reinterpret_cast<Node *>(p.begin())); } return -1; } diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 60d6921..2737a87 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -543,7 +543,7 @@ void QVector<T>::append(const T &t) template <typename T> Q_TYPENAME QVector<T>::iterator QVector<T>::insert(iterator before, size_type n, const T &t) { - int offset = before - p->array; + int offset = int(before - p->array); if (n != 0) { const T copy(t); if (d->ref != 1 || d->size + n > d->alloc) @@ -577,8 +577,8 @@ Q_TYPENAME QVector<T>::iterator QVector<T>::insert(iterator before, size_type n, template <typename T> Q_TYPENAME QVector<T>::iterator QVector<T>::erase(iterator abegin, iterator aend) { - int f = abegin - p->array; - int l = aend - p->array; + int f = int(abegin - p->array); + int l = int(aend - p->array); int n = l - f; detach(); if (QTypeInfo<T>::isComplex) { diff --git a/src/gui/kernel/qsizepolicy.h b/src/gui/kernel/qsizepolicy.h index b0c6e9a..2914a21 100644 --- a/src/gui/kernel/qsizepolicy.h +++ b/src/gui/kernel/qsizepolicy.h @@ -224,8 +224,8 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &); inline void QSizePolicy::transpose() { Policy hData = horizontalPolicy(); Policy vData = verticalPolicy(); - uchar hStretch = horizontalStretch(); - uchar vStretch = verticalStretch(); + uchar hStretch = uchar(horizontalStretch()); + uchar vStretch = uchar(verticalStretch()); setHorizontalPolicy(vData); setVerticalPolicy(hData); setHorizontalStretch(vStretch); |