From d27360818d78adc412c4fb7012c8d5c0b2f38d98 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Fri, 21 Oct 2022 16:13:50 +0200 Subject: QString: add unittest to verify erase() returns a QString::iterator Not a const_iterator. Change-Id: I0a9db7cdd956541e0be6e748b084b502fcc1e563 Reviewed-by: Thiago Macieira --- tests/auto/corelib/text/qstring/tst_qstring.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index 8b9e762d5d..6a40d511e6 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -3505,6 +3505,16 @@ void tst_QString::erase() it = s.erase(s.begin(), s.begin() + 1); QCOMPARE_EQ(s, "b"); QCOMPARE(it, s.begin()); + + { + QString s1 = QLatin1String("house"); + QString copy = s1; + // erase() should return an iterator, not const_iterator + auto it = s1.erase(s1.cbegin(), s1.cbegin()); + *it = QLatin1Char('m'); + QCOMPARE(s1, "mouse"); + QCOMPARE(copy, "house"); + } } void tst_QString::toNum() -- cgit v1.2.3