diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-08-29 19:13:15 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-11-16 12:32:01 +0100 |
commit | fc80bd201c7ee583254ec90eefcb16f550127cd1 (patch) | |
tree | 9ce8f91c3b56ca9f2d37e92804839ad60df73e0f /src/corelib/tools/qlist.h | |
parent | aa136d46e100e65f0d9326ac9319de95673cd6d7 (diff) |
Fix error on MSVC when QList with disabled rvalues is instantiated
MSVC does in some case full instantiation of the template. Make sure
all of it expands to valid C++, even in the case where those methods
are supposed to be disabled.
Fixes: QTBUG-86289
Change-Id: Iaae39ef60fc5cf5fee273b0934a5a52b6ae4ec17
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/tools/qlist.h')
-rw-r--r-- | src/corelib/tools/qlist.h | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index f85d4c3610..27be22fc1f 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -312,7 +312,14 @@ public: const_reference operator[](qsizetype i) const noexcept { return at(i); } void append(parameter_type t) { emplaceBack(t); } void append(const_iterator i1, const_iterator i2); - void append(rvalue_ref t) { emplaceBack(std::move(t)); } + void append(rvalue_ref t) + { + if constexpr (DataPointer::pass_parameter_by_value) { + Q_UNUSED(t); + } else { + emplaceBack(std::move(t)); + } + } void append(const QList<T> &l) { // protect against l == *this @@ -320,7 +327,13 @@ public: append(list.constBegin(), list.constEnd()); } void append(QList<T> &&l); - void prepend(rvalue_ref t) { emplaceFront(std::move(t)); } + void prepend(rvalue_ref t) { + if constexpr (DataPointer::pass_parameter_by_value) { + Q_UNUSED(t); + } else { + emplaceFront(std::move(t)); + } + } void prepend(parameter_type t) { emplaceFront(t); } template<typename... Args> @@ -347,7 +360,15 @@ public: Q_ASSERT_X(isValidIterator(before), "QList::insert", "The specified iterator argument 'before' is invalid"); return insert(std::distance(constBegin(), before), std::move(t)); } - iterator insert(qsizetype i, rvalue_ref t) { return emplace(i, std::move(t)); } + iterator insert(qsizetype i, rvalue_ref t) { + if constexpr (DataPointer::pass_parameter_by_value) { + Q_UNUSED(i); + Q_UNUSED(t); + return end(); + } else { + return emplace(i, std::move(t)); + } + } template <typename ...Args> iterator emplace(const_iterator before, Args&&... args) @@ -371,9 +392,14 @@ public: } void replace(qsizetype i, rvalue_ref t) { - Q_ASSERT_X(i >= 0 && i < d->size, "QList<T>::replace", "index out of range"); - const T copy(std::move(t)); - data()[i] = std::move(copy); + if constexpr (DataPointer::pass_parameter_by_value) { + Q_UNUSED(i); + Q_UNUSED(t); + } else { + Q_ASSERT_X(i >= 0 && i < d->size, "QList<T>::replace", "index out of range"); + const T copy(std::move(t)); + data()[i] = std::move(copy); + } } void remove(qsizetype i, qsizetype n = 1); |