Details
Description
QUrlQuery has no move constructor despite having swap and move assignment. Because QUrlQuery fails to implement rule-of-5 this breaks types that have QUrlQuery members from being able to rely on rule-of-0.
static_assert(std::is_nothrow_move_assignable_v<QUrlQuery>); // ok static_assert(std::is_nothrow_move_constructible_v<QUrlQuery>); // fails
Workaround for types that want to rely on rule-of-0: default 4 special member functions and implement move constructor by swapping QUrlQuery objects.
class X { public: X() = default; ~X() = default; X(const X& other) = default; X& operator=(const X& other) = default; X(X&& other) noexcept // (std::move all members here except QUrlQuery) // (QUrlQuery will be default-constructed) { query.swap(other.query); } X& operator=(X&& other) noexcept = default; private: // other members... QUrlQuery query; };
Attachments
For Gerrit Dashboard: QTBUG-109842 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
452257,3 | QUrlQuery: add missing move constructor | dev | qt/qtbase | Status: MERGED | +2 | 0 |
455240,2 | QUrlQuery: add missing move constructor | 6.5 | qt/qtbase | Status: MERGED | +2 | 0 |
455331,2 | tst_QUrlQuery: fix Clang 15 -Wself-move | dev | qt/qtbase | Status: MERGED | +2 | 0 |
455679,2 | tst_QUrlQuery: fix Clang 15 -Wself-move | 6.5 | qt/qtbase | Status: MERGED | +2 | 0 |