diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-05-08 17:05:29 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-05-14 14:19:47 +0200 |
commit | 594abde1a257a95ef33634a950a6429ac33d2b76 (patch) | |
tree | 8ab4ee79cd6147b5d9cce481d9fdbc98920a5b72 /tests/auto/corelib/text/qstring | |
parent | af3caa2271f47ddf48da46a0cc5932aaa442eb39 (diff) |
Enforce that statically allocated array-like containers have 0 capacity
It has been the case for both QStringLiteral and QByteArrayLiteral
since Qt 5.0, and Q_ARRAY_LITERAL since Qt 6.0.
Since it's definitely surprising, add a note in the docs, which
is "somehow" consistent with the interpretation of capacity as
the biggest possible size before we reallocate. Since it's 0,
any manipulation of the size will cause a reallocation.
(Alternatively: the capacity() is for how many elements memory was
requested from the free store. No memory was allocated, so 0...)
Task-number: QTBUG-84069
Change-Id: I5c7d21a22d1bd8b8d9b71143e33d537ca0224acd
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/text/qstring')
-rw-r--r-- | tests/auto/corelib/text/qstring/tst_qstring.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index 8af644d012..cefcd4f2e5 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -6543,18 +6543,22 @@ void tst_QString::literals() QString str(QStringLiteral("abcd")); QVERIFY(str.length() == 4); + QCOMPARE(str.capacity(), 0); QVERIFY(str == QLatin1String("abcd")); QVERIFY(str.data_ptr()->isStatic()); const QChar *s = str.constData(); QString str2 = str; QVERIFY(str2.constData() == s); + QCOMPARE(str2.capacity(), 0); // detach on non const access QVERIFY(str.data() != s); + QVERIFY(str.capacity() >= str.length()); QVERIFY(str2.constData() == s); QVERIFY(str2.data() != s); + QVERIFY(str2.capacity() >= str2.length()); } #endif |