diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-02-15 00:11:22 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-06-10 16:49:08 +0200 |
commit | 8e98a161e993c6636d217276a0f2373d642ff050 (patch) | |
tree | 23adce823bfab9795cf7b775d35f14be7baedc10 /tests | |
parent | ce5931aaf2c9698925366e787d08747a1c60c378 (diff) |
Long live std::pair!
Make QPair an alias for std::pair, and qMakePair just a forwarder
towards std::make_pair.
Why? Fundamentally to ditch a bunch of NIH code; gain for free
structured bindings, std::tuple and std::reference_wrapper
compatibility, and so on.
Breakages:
* Some that code manually forward declares QPair.
We don't care about it (<QContainerFwd> is the proper way).
* Some code that overloads on std::pair and QPair. Luckily
it's mostly centralized: debug, metatypes, testing macros.
Just remove the QPair overload.
* Usages of qMakePair forcing the template type parameters.
There are a handful of these in qtbase, but only one was actually
broken.
* std::pair is NOT (and will never likely be) trivially copiable.
This is agreed to be a mistake done by practically all implementations
in C++11, can can't be fixed without breaking ABI.
Some code using QPair assuming it's trivially copiable may break;
exactly one occurrence was in qtbase.
* QMetaType logic extracts the type names in two different ways,
one by looking at the source code string (e.g. extracted by moc)
and one via some ad-hoc reflection in C++. We need to make
"QPair" (as spelled in the source code) be the same as "std::pair"
(gathered via reflection, which will see through the alias)
when compared. The way it's already done e.g. for QList is
by actually replacing the moc-extracted name with the name
of the actual type used in C++; do the same here.
On libc++, std::pair is actually in an inline namespace --
i.e. std::__1::pair; the reflection will extract and store
"std::__1::pair" so we need an ad-hoc fix to QMetaType.
[ChangeLog][QtCore][QPair] QPair is now an alias to std::pair,
and does not exist as a class in Qt any more. This may break
code such as functions overloaded for both QPair and std::pair.
Usually, the overload taking a QPair can be safely discarded,
leaving only the one taking a std::pair. QPair API has not changed,
and qMakePair is still available for compatibility (although
new code is encouraged to use std::pair and std::make_pair
directly instead).
Change-Id: I7725c751bf23946cde577b1406e86a336c0a3dcf
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests')
11 files changed, 30 insertions, 26 deletions
diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp index 9db2bb241a..0091636172 100644 --- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp +++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp @@ -1381,7 +1381,12 @@ void tst_QMetaObject::normalizedType_data() QTest::newRow("template6") << "QVector<::Foo::Bar>" << "QVector<::Foo::Bar>"; QTest::newRow("template7") << "QVector<QVector<int> >" << "QVector<QVector<int>>"; QTest::newRow("template8") << "QMap<const int, const short*>" << "QMap<const int,const short*>"; - QTest::newRow("template9") << "QPair<const QPair<int, int const *> , QPair<QHash<int, const char*> > >" << "QPair<const QPair<int,const int*>,QPair<QHash<int,const char*>>>"; + QTest::newRow("template9") << "QPair<const QPair<int, int const *> , QPair<QHash<int, const char*> > >" +#ifdef _LIBCPP_VERSION + << "std::__1::pair<const std::__1::pair<int,const int*>,std::__1::pair<QHash<int,const char*>>>"; +#else + << "std::pair<const std::pair<int,const int*>,std::pair<QHash<int,const char*>>>"; +#endif QTest::newRow("template10") << "QList<int const * const> const" << "QVector<const int*const>"; QTest::newRow("template11") << " QSharedPointer<QVarLengthArray< QString const, ( 16>> 2 )> > const & " << "QSharedPointer<QVarLengthArray<const QString,(16>>2)>>"; diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index d036be55c6..2688d90b43 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -1640,7 +1640,7 @@ void tst_QMetaType::automaticTemplateRegistration() QCOMPARE(QVariant::fromValue(intIntPair).value<IntIntPair>().second, 2); } { - IntUIntPair intUIntPair = qMakePair<int, uint>(4, 2); + IntUIntPair intUIntPair = qMakePair(4, 2u); QCOMPARE(QVariant::fromValue(intUIntPair).value<IntUIntPair>().first, 4); QCOMPARE(QVariant::fromValue(intUIntPair).value<IntUIntPair>().second, (uint)2); } @@ -1727,7 +1727,7 @@ void tst_QMetaType::automaticTemplateRegistration() #define FOR_EACH_2ARG_TEMPLATE_TYPE(F, RealName1, RealName2) \ F(QHash, RealName1, RealName2) \ F(QMap, RealName1, RealName2) \ - F(QPair, RealName1, RealName2) + F(std::pair, RealName1, RealName2) #define PRINT_2ARG_TEMPLATE_INTERNAL(RealName1, RealName2) \ FOR_EACH_2ARG_TEMPLATE_TYPE(CREATE_AND_VERIFY_CONTAINER, RealName1, RealName2) @@ -1753,7 +1753,7 @@ void tst_QMetaType::automaticTemplateRegistration() CREATE_AND_VERIFY_CONTAINER(QVector, void*) CREATE_AND_VERIFY_CONTAINER(QVector, const void*) CREATE_AND_VERIFY_CONTAINER(QList, void*) - CREATE_AND_VERIFY_CONTAINER(QPair, void*, void*) + CREATE_AND_VERIFY_CONTAINER(std::pair, void*, void*) CREATE_AND_VERIFY_CONTAINER(QHash, void*, void*) CREATE_AND_VERIFY_CONTAINER(QHash, const void*, const void*) diff --git a/tests/auto/corelib/tools/qpair/qpair.pro b/tests/auto/corelib/tools/qpair/qpair.pro index d684a24a57..39757d3e0f 100644 --- a/tests/auto/corelib/tools/qpair/qpair.pro +++ b/tests/auto/corelib/tools/qpair/qpair.pro @@ -3,5 +3,4 @@ TARGET = tst_qpair QT = core testlib SOURCES = tst_qpair.cpp -# Force C++17 if available (needed due to Q_COMPILER_DEDUCTION_GUIDES) -contains(QT_CONFIG, c++1z): CONFIG += c++1z +contains(QT_CONFIG, c++2a): CONFIG += c++2a diff --git a/tests/auto/corelib/tools/qpair/tst_qpair.cpp b/tests/auto/corelib/tools/qpair/tst_qpair.cpp index 3c972329bc..0a158e5860 100644 --- a/tests/auto/corelib/tools/qpair/tst_qpair.cpp +++ b/tests/auto/corelib/tools/qpair/tst_qpair.cpp @@ -39,7 +39,7 @@ private Q_SLOTS: void testConstexpr(); void testConversions(); void taskQTBUG_48780_pairContainingCArray(); - void testDeducationRules(); + void testDeductionRules(); }; class C { C() {} char _[4]; }; @@ -203,9 +203,9 @@ void tst_QPair::taskQTBUG_48780_pairContainingCArray() Q_UNUSED(pair); } -void tst_QPair::testDeducationRules() +void tst_QPair::testDeductionRules() { -#if defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201606 +#if defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201907L QPair p1{1, 2}; static_assert(std::is_same<decltype(p1)::first_type, decltype(1)>::value); static_assert(std::is_same<decltype(p1)::second_type, decltype(2)>::value); @@ -224,7 +224,7 @@ void tst_QPair::testDeducationRules() QCOMPARE(p3.first, "string"); QCOMPARE(p3.second, 2); #else - QSKIP("Unsupported"); + QSKIP("Unsupported (requires C++20's CTAD for aliases)"); #endif } diff --git a/tests/auto/network/kernel/qauthenticator/tst_qauthenticator.cpp b/tests/auto/network/kernel/qauthenticator/tst_qauthenticator.cpp index 8cef351554..94a998a6a6 100644 --- a/tests/auto/network/kernel/qauthenticator/tst_qauthenticator.cpp +++ b/tests/auto/network/kernel/qauthenticator/tst_qauthenticator.cpp @@ -82,7 +82,7 @@ void tst_QAuthenticator::basicAuth() QCOMPARE(priv->phase, QAuthenticatorPrivate::Start); QList<QPair<QByteArray, QByteArray> > headers; - headers << qMakePair<QByteArray, QByteArray>(QByteArray("WWW-Authenticate"), "Basic " + data.toUtf8()); + headers << qMakePair(QByteArray("WWW-Authenticate"), "Basic " + data.toUtf8()); priv->parseHttpResponse(headers, /*isProxy = */ false); QCOMPARE(auth.realm(), realm); @@ -130,7 +130,7 @@ void tst_QAuthenticator::ntlmAuth() // This phase of NTLM contains no information, other than what we're willing to negotiate // Current implementation uses flags: // NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_REQUEST_TARGET - headers << qMakePair<QByteArray, QByteArray>("WWW-Authenticate", "NTLM"); + headers << qMakePair(QByteArrayLiteral("WWW-Authenticate"), QByteArrayLiteral("NTLM")); priv->parseHttpResponse(headers, /*isProxy = */ false); if (sso) QVERIFY(priv->calculateResponse("GET", "/", "").startsWith("NTLM ")); @@ -139,7 +139,7 @@ void tst_QAuthenticator::ntlmAuth() // NTLM phase 2: challenge headers.clear(); - headers << qMakePair<QByteArray, QByteArray>(QByteArray("WWW-Authenticate"), "NTLM " + data.toUtf8()); + headers << qMakePair(QByteArray("WWW-Authenticate"), "NTLM " + data.toUtf8()); priv->parseHttpResponse(headers, /*isProxy = */ false); QEXPECT_FAIL("with-realm", "NTLM authentication code doesn't extract the realm", Continue); diff --git a/tests/auto/testlib/selftests/expected_pairdiagnostics.junitxml b/tests/auto/testlib/selftests/expected_pairdiagnostics.junitxml index cf2a30b84a..653dde11c0 100644 --- a/tests/auto/testlib/selftests/expected_pairdiagnostics.junitxml +++ b/tests/auto/testlib/selftests/expected_pairdiagnostics.junitxml @@ -8,8 +8,8 @@ <testcase result="pass" name="initTestCase"/> <testcase result="fail" name="testQPair"> <failure message="Compared values are not the same - Actual (pair1): "QPair(1,1)" - Expected (pair2): "QPair(1,2)"" result="fail"/> + Actual (pair1): "std::pair(1,1)" + Expected (pair2): "std::pair(1,2)"" result="fail"/> </testcase> <testcase result="fail" name="testStdPair"> <failure message="Compared values are not the same diff --git a/tests/auto/testlib/selftests/expected_pairdiagnostics.lightxml b/tests/auto/testlib/selftests/expected_pairdiagnostics.lightxml index 7a842e9d36..e4ceacc9e3 100644 --- a/tests/auto/testlib/selftests/expected_pairdiagnostics.lightxml +++ b/tests/auto/testlib/selftests/expected_pairdiagnostics.lightxml @@ -10,8 +10,8 @@ <TestFunction name="testQPair"> <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp" line="0"> <Description><![CDATA[Compared values are not the same - Actual (pair1): "QPair(1,1)" - Expected (pair2): "QPair(1,2)"]]></Description> + Actual (pair1): "std::pair(1,1)" + Expected (pair2): "std::pair(1,2)"]]></Description> </Incident> <Duration msecs="0"/> </TestFunction> diff --git a/tests/auto/testlib/selftests/expected_pairdiagnostics.tap b/tests/auto/testlib/selftests/expected_pairdiagnostics.tap index 9c45880c2d..d6e1a0b22f 100644 --- a/tests/auto/testlib/selftests/expected_pairdiagnostics.tap +++ b/tests/auto/testlib/selftests/expected_pairdiagnostics.tap @@ -5,10 +5,10 @@ not ok 2 - testQPair() --- type: QCOMPARE message: Compared values are not the same - wanted: "QPair(1,2)" (pair2) - found: "QPair(1,1)" (pair1) - expected: "QPair(1,2)" (pair2) - actual: "QPair(1,1)" (pair1) + wanted: "std::pair(1,2)" (pair2) + found: "std::pair(1,1)" (pair1) + expected: "std::pair(1,2)" (pair2) + actual: "std::pair(1,1)" (pair1) at: tst_PairDiagnostics::testQPair() (qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp:51) file: qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp line: 51 diff --git a/tests/auto/testlib/selftests/expected_pairdiagnostics.teamcity b/tests/auto/testlib/selftests/expected_pairdiagnostics.teamcity index 9068e2c45b..a86f4fa254 100644 --- a/tests/auto/testlib/selftests/expected_pairdiagnostics.teamcity +++ b/tests/auto/testlib/selftests/expected_pairdiagnostics.teamcity @@ -2,7 +2,7 @@ ##teamcity[testStarted name='initTestCase()' flowId='tst_PairDiagnostics'] ##teamcity[testFinished name='initTestCase()' flowId='tst_PairDiagnostics'] ##teamcity[testStarted name='testQPair()' flowId='tst_PairDiagnostics'] -##teamcity[testFailed name='testQPair()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp(0)|]' details='Compared values are not the same|n Actual (pair1): "QPair(1,1)"|n Expected (pair2): "QPair(1,2)"' flowId='tst_PairDiagnostics'] +##teamcity[testFailed name='testQPair()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp(0)|]' details='Compared values are not the same|n Actual (pair1): "std::pair(1,1)"|n Expected (pair2): "std::pair(1,2)"' flowId='tst_PairDiagnostics'] ##teamcity[testFinished name='testQPair()' flowId='tst_PairDiagnostics'] ##teamcity[testStarted name='testStdPair()' flowId='tst_PairDiagnostics'] ##teamcity[testFailed name='testStdPair()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp(0)|]' details='Compared values are not the same|n Actual (pair1): "std::pair(1,1)"|n Expected (pair2): "std::pair(1,2)"' flowId='tst_PairDiagnostics'] diff --git a/tests/auto/testlib/selftests/expected_pairdiagnostics.txt b/tests/auto/testlib/selftests/expected_pairdiagnostics.txt index 5e29888ba6..cbb8b764ff 100644 --- a/tests/auto/testlib/selftests/expected_pairdiagnostics.txt +++ b/tests/auto/testlib/selftests/expected_pairdiagnostics.txt @@ -2,8 +2,8 @@ Config: Using QtTest library PASS : tst_PairDiagnostics::initTestCase() FAIL! : tst_PairDiagnostics::testQPair() Compared values are not the same - Actual (pair1): "QPair(1,1)" - Expected (pair2): "QPair(1,2)" + Actual (pair1): "std::pair(1,1)" + Expected (pair2): "std::pair(1,2)" Loc: [qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp(0)] FAIL! : tst_PairDiagnostics::testStdPair() Compared values are not the same Actual (pair1): "std::pair(1,1)" diff --git a/tests/auto/testlib/selftests/expected_pairdiagnostics.xml b/tests/auto/testlib/selftests/expected_pairdiagnostics.xml index cd98e4d36e..89e8ca49a6 100644 --- a/tests/auto/testlib/selftests/expected_pairdiagnostics.xml +++ b/tests/auto/testlib/selftests/expected_pairdiagnostics.xml @@ -12,8 +12,8 @@ <TestFunction name="testQPair"> <Incident type="fail" file="qtbase/tests/auto/testlib/selftests/pairdiagnostics/tst_pairdiagnostics.cpp" line="0"> <Description><![CDATA[Compared values are not the same - Actual (pair1): "QPair(1,1)" - Expected (pair2): "QPair(1,2)"]]></Description> + Actual (pair1): "std::pair(1,1)" + Expected (pair2): "std::pair(1,2)"]]></Description> </Incident> <Duration msecs="0"/> </TestFunction> |