summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2017-03-17 11:07:30 +0100
committerMarc Mutz <marc.mutz@kdab.com>2017-03-17 20:28:32 +0000
commit5c724a6087b0a647e8241d35f0d44bce08e35281 (patch)
tree79a2c5cfe795303f1e2fb68135a7bf689cec39d3 /tests/auto/corelib/tools
parent4ee74257940e2ed21b653b986ad02a746e8438a6 (diff)
QChar: fix ambiguous comparisons with 0, '\0', ... for good
Commit e0ea0f6178c9dbee2a8c888fde84ad1cd9670c6b optimized QChar <-> QString(Ref) comparisons by adding more overloads to avoid creating QStrings from QChars just to compare them. But these new overloads made existing comparisons to QChar ambiguous. This was known at the time for QChar/int comparisons. It has since turned out that also comparing to '\0' is ambiguous, ie. not comparing to int or char per se is ambiguous, but comparing to nullptr constants is, because QString(const char*) is just as good a candidate as QChar(char)/QChar(int). Since we allow QString/QChar comparisons, it seems logical to solve the problem by adding QChar<->nullptr overloads. [ChangeLog][QtCore][QChar] Disambiguated comparisons with nullptr constants such as '\0', which 5.8.0 broke. As a consequence, QChar<->int comparisons are no longer deprecated, as this was a failed attempt at fixing the ambiguity. Change-Id: I680dd509c2286e96894e13078899dbe3b2dd83bc Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/qchar/tst_qchar.cpp61
1 files changed, 40 insertions, 21 deletions
diff --git a/tests/auto/corelib/tools/qchar/tst_qchar.cpp b/tests/auto/corelib/tools/qchar/tst_qchar.cpp
index fb436b67d6..b42be94da3 100644
--- a/tests/auto/corelib/tools/qchar/tst_qchar.cpp
+++ b/tests/auto/corelib/tools/qchar/tst_qchar.cpp
@@ -36,7 +36,7 @@ class tst_QChar : public QObject
{
Q_OBJECT
private slots:
- void operator_eqeq_int();
+ void operator_eqeq_null();
void operators_data();
void operators();
void toUpper();
@@ -72,35 +72,54 @@ private slots:
void unicodeVersion();
};
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_DEPRECATED
-
-void tst_QChar::operator_eqeq_int()
+void tst_QChar::operator_eqeq_null()
{
{
const QChar ch = QLatin1Char(' ');
- QVERIFY(ch != 0);
- QVERIFY(!(ch == 0));
-
- QVERIFY(ch == 0x20);
- QVERIFY(!(ch != 0x20));
- QVERIFY(0x20 == ch);
- QVERIFY(!(0x20 != ch));
+#define CHECK(NUL) \
+ do { \
+ QVERIFY(!(ch == NUL)); \
+ QVERIFY( ch != NUL ); \
+ QVERIFY(!(ch < NUL)); \
+ QVERIFY( ch > NUL ); \
+ QVERIFY(!(ch <= NUL)); \
+ QVERIFY( ch >= NUL ); \
+ QVERIFY(!(NUL == ch )); \
+ QVERIFY( NUL != ch ); \
+ QVERIFY( NUL < ch ); \
+ QVERIFY(!(NUL > ch )); \
+ QVERIFY( NUL <= ch ); \
+ QVERIFY(!(NUL >= ch )); \
+ } while (0)
+
+ CHECK(0);
+ CHECK('\0');
+#undef CHECK
}
{
const QChar ch = QLatin1Char('\0');
- QVERIFY(ch == 0);
- QVERIFY(!(ch != 0));
-
- QVERIFY(ch != 0x20);
- QVERIFY(!(ch == 0x20));
- QVERIFY(0x20 != ch);
- QVERIFY(!(0x20 == ch));
+#define CHECK(NUL) \
+ do { \
+ QVERIFY( ch == NUL ); \
+ QVERIFY(!(ch != NUL)); \
+ QVERIFY(!(ch < NUL)); \
+ QVERIFY(!(ch > NUL)); \
+ QVERIFY( ch <= NUL ); \
+ QVERIFY( ch >= NUL ); \
+ QVERIFY( NUL == ch ); \
+ QVERIFY(!(NUL != ch )); \
+ QVERIFY(!(NUL < ch )); \
+ QVERIFY(!(NUL > ch )); \
+ QVERIFY( NUL <= ch ); \
+ QVERIFY( NUL >= ch ); \
+ } while (0)
+
+ CHECK(0);
+ CHECK('\0');
+#undef CHECK
}
}
-QT_WARNING_POP
-
void tst_QChar::operators_data()
{
QTest::addColumn<QChar>("lhs");