From 62e6aa6195680fde73807bab3a43c63f10c585f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Bj=C3=B8rlykke?= Date: Tue, 28 Feb 2017 09:42:08 +0100 Subject: QVector: Avoid implicit conversion warnings This fixes compiling an application using QVector and -Wshorten-64-to-32 on a 64-bit system without getting this warning: ... 5.8/clang_64/lib/QtCore.framework/Headers/qvector.h:695:18: warning: implicit conversion loses integer precision: 'typename iterator_traits::difference_type' (aka 'long') to 'int' [-Wshorten-64-to-32] int offset = std::distance(d->begin(), before); ~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ... 5.8/clang_64/lib/QtCore.framework/Headers/qvector.h:731:35: warning: implicit conversion loses integer precision: 'long' to 'const int' [-Wshorten-64-to-32] const int itemsToErase = aend - abegin; ~~~~~~~~~~~~ ~~~~~^~~~~~~~ ... 5.8/clang_64/lib/QtCore.framework/Headers/qvector.h:740:39: warning: implicit conversion loses integer precision: 'long' to 'const int' [-Wshorten-64-to-32] const int itemsUntouched = abegin - d->begin(); ~~~~~~~~~~~~~~ ~~~~~~~^~~~~~~~~~~~ Change-Id: I52d85908f4aac20c7e9ac8063ac760ce52f85541 Reviewed-by: Marc Mutz Reviewed-by: Thiago Macieira --- src/corelib/tools/qvector.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/corelib/tools/qvector.h') diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 5225b68d40..a526d35ddc 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -692,7 +692,7 @@ typename QVector::iterator QVector::insert(iterator before, size_type n, c { Q_ASSERT_X(isValidIterator(before), "QVector::insert", "The specified iterator argument 'before' is invalid"); - int offset = std::distance(d->begin(), before); + const auto offset = std::distance(d->begin(), before); if (n != 0) { const T copy(t); if (!isDetached() || d->size + n > int(d->alloc)) @@ -728,7 +728,7 @@ typename QVector::iterator QVector::erase(iterator abegin, iterator aend) Q_ASSERT_X(isValidIterator(abegin), "QVector::erase", "The specified iterator argument 'abegin' is invalid"); Q_ASSERT_X(isValidIterator(aend), "QVector::erase", "The specified iterator argument 'aend' is invalid"); - const int itemsToErase = aend - abegin; + const auto itemsToErase = aend - abegin; if (!itemsToErase) return abegin; @@ -737,7 +737,7 @@ typename QVector::iterator QVector::erase(iterator abegin, iterator aend) Q_ASSERT(aend <= d->end()); Q_ASSERT(abegin <= aend); - const int itemsUntouched = abegin - d->begin(); + const auto itemsUntouched = abegin - d->begin(); // FIXME we could do a proper realloc, which copy constructs only needed data. // FIXME we are about to delete data - maybe it is good time to shrink? @@ -766,7 +766,7 @@ typename QVector::iterator QVector::erase(iterator abegin, iterator aend) memmove(static_cast(abegin), static_cast(aend), (d->size - itemsToErase - itemsUntouched) * sizeof(T)); } - d->size -= itemsToErase; + d->size -= int(itemsToErase); } return d->begin() + itemsUntouched; } -- cgit v1.2.3