diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2023-01-05 10:06:33 -0300 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-01-20 03:19:21 +0000 |
commit | fc8dad2f10e7976cfa778ca7d75e651012629b21 (patch) | |
tree | c0a90c896f76388d5c03ddb7998dd9d435a81086 | |
parent | 3d584b1093cdb6245b02eda996db2927ffaf09ea (diff) |
QUrlQuery: add missing move constructor
It wasn't added when this class was created in 5.0 because we couldn't
add move constructors and still keep the ability to compile Qt with
C++98 compilers. We've forgot to correct this shortcoming since 5.6.
Fixes: QTBUG-109842
Pick-to: 6.5
Change-Id: I69ecc04064514f939896fffd17376b8243b73c52
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
-rw-r--r-- | src/corelib/io/qurlquery.cpp | 10 | ||||
-rw-r--r-- | src/corelib/io/qurlquery.h | 1 | ||||
-rw-r--r-- | tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp | 24 |
3 files changed, 35 insertions, 0 deletions
diff --git a/src/corelib/io/qurlquery.cpp b/src/corelib/io/qurlquery.cpp index 57e66142ca..d90c80be6d 100644 --- a/src/corelib/io/qurlquery.cpp +++ b/src/corelib/io/qurlquery.cpp @@ -364,6 +364,16 @@ QUrlQuery::QUrlQuery(const QUrlQuery &other) } /*! + \since 6.5 + Moves the contents of the \a other QUrlQuery object, including the query + delimiters. +*/ +QUrlQuery::QUrlQuery(QUrlQuery &&other) noexcept + : d(std::move(other.d)) +{ +} + +/*! Copies the contents of the \a other QUrlQuery object, including the query delimiters. */ diff --git a/src/corelib/io/qurlquery.h b/src/corelib/io/qurlquery.h index 16dcc44ff2..411f19a4c8 100644 --- a/src/corelib/io/qurlquery.h +++ b/src/corelib/io/qurlquery.h @@ -30,6 +30,7 @@ public: } QUrlQuery(const QUrlQuery &other); + QUrlQuery(QUrlQuery &&other) noexcept; QUrlQuery &operator=(const QUrlQuery &other); QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QUrlQuery) ~QUrlQuery(); diff --git a/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp b/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp index 41482f4256..deb6fce563 100644 --- a/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp +++ b/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp @@ -172,6 +172,7 @@ void tst_QUrlQuery::constructing() QVERIFY(other != empty); QVERIFY(!(other == empty)); + // copy-construct QUrlQuery copy(other); QCOMPARE(copy, other); @@ -179,10 +180,33 @@ void tst_QUrlQuery::constructing() QVERIFY(copy.isEmpty()); QVERIFY(copy != other); + // copy-assign copy = other; QVERIFY(!copy.isEmpty()); QCOMPARE(copy, other); + // move-construct + QUrlQuery moved(std::move(other)); + QCOMPARE(moved, copy); + + // self move-assign + moved = std::move(moved); + QCOMPARE(moved, copy); + + // self move-assign of moved-from (Hinnant Criterion) + other = std::move(other); + // shouldn't crash; here, or further down + + // copy-assign to moved-from object + other = copy; + QCOMPARE(other, copy); + QCOMPARE(other, moved); + + // move-assign + moved = std::move(other); + QCOMPARE(moved, copy); + + // (move-)assign default-constructed copy = QUrlQuery(); QVERIFY(copy.isEmpty()); |