summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qstringalgorithms_p.h2
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp9
2 files changed, 10 insertions, 1 deletions
diff --git a/src/corelib/tools/qstringalgorithms_p.h b/src/corelib/tools/qstringalgorithms_p.h
index 1481b194eb..b4be5c7ec7 100644
--- a/src/corelib/tools/qstringalgorithms_p.h
+++ b/src/corelib/tools/qstringalgorithms_p.h
@@ -114,7 +114,7 @@ template <typename StringType> struct QStringAlgorithms
return str;
const Char *src = str.cbegin();
const Char *end = str.cend();
- NakedStringType result = isConst ?
+ NakedStringType result = isConst || !str.isDetached() ?
StringType(str.size(), Qt::Uninitialized) :
qMove(str);
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
index 52c3e65a24..8cd9610542 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -2040,6 +2040,9 @@ void tst_QString::simplified()
QFETCH(QString, full);
QFETCH(QString, simple);
+ QString orig_full = full;
+ orig_full.data(); // forces a detach
+
QString result = full.simplified();
if (simple.isNull()) {
QVERIFY2(result.isNull(), qPrintable("'" + full + "' did not yield null: " + result));
@@ -2048,6 +2051,12 @@ void tst_QString::simplified()
} else {
QCOMPARE(result, simple);
}
+ QCOMPARE(full, orig_full);
+
+ // without detaching:
+ QString copy1 = full;
+ QCOMPARE(qMove(full).simplified(), simple);
+ QCOMPARE(full, orig_full);
// force a detach
if (!full.isEmpty())