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/corelib/tools | |
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/corelib/tools')
-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 |
6 files changed, 25 insertions, 25 deletions
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) { |