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.

Pick-to: 6.2 6.5
Change-Id: I521eca26a48aed570855b13242bf2df8bfa38f96
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Edward Welbourne 2023-04-21 15:46:21 +02:00 committed by Thiago Macieira
parent e0cec08480
commit 3fd7086878

View File

@ -274,7 +274,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());
@ -282,7 +282,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;
@ -295,7 +295,7 @@ public:
} else {
const auto distance = std::distance(i1, i2);
if (distance) {
d = DataPointer(Data::allocate(distance));
d = DataPointer(Data::allocate(qsizetype(distance)));
// appendIteratorRange can deal with contiguous iterators on its own,
// this is an optimization for C++17 code.
if constexpr (std::is_same_v<std::decay_t<InputIterator>, iterator> ||