Silence MSVC warning on constructing QList from initializer_list

MSVC complains because we call Data::allocate(args.size()) and, of
course, initializer_list::size() returns unsigned std::size_type,
while the relevant Data::allocate() overload takes a signed qsizetype.

The constructor from iterators potentially has the same problem, if
the iterator type's difference_type is unsigned, so make the
type-conversion overt there, too.

Change-Id: I521eca26a48aed570855b13242bf2df8bfa38f96
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 3fd7086878ea03861fc82348fc5b4e77f76b2a86)
Reviewed-by: Mate Barany <mate.barany@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Edward Welbourne 2023-04-21 15:46:21 +02:00
parent 095342b16f
commit 3fef1a7991

View File

@ -260,7 +260,7 @@ public:
}
inline QList(std::initializer_list<T> args)
: d(Data::allocate(args.size()))
: d(Data::allocate(qsizetype(args.size())))
{
if (args.size())
d->copyAppend(args.begin(), args.end());
@ -268,7 +268,7 @@ public:
QList<T> &operator=(std::initializer_list<T> args)
{
d = DataPointer(Data::allocate(args.size()));
d = DataPointer(Data::allocate(qsizetype(args.size())));
if (args.size())
d->copyAppend(args.begin(), args.end());
return *this;
@ -281,7 +281,7 @@ public:
} else {
const auto distance = std::distance(i1, i2);
if (distance) {
d = DataPointer(Data::allocate(distance));
d = DataPointer(Data::allocate(qsizetype(distance)));
if constexpr (std::is_same_v<std::decay_t<InputIterator>, iterator> ||
std::is_same_v<std::decay_t<InputIterator>, const_iterator>) {
d->copyAppend(i1, i2);