summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-12-02 12:24:41 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-12-03 06:51:14 +0100
commit427da064144a63cebb8f4ad0f053f96c9aceacd8 (patch)
treeefea77c04db8dde9d088e939ec90cc742b1dea2e /src
parent1ebccf3426ef407d174fd9cdfd22da742111331e (diff)
QRE: discourage users from assuming that QRE stores the subject
When matching over a QString we store a (shallow) copy of it. That has always been an implementation detail and people should've never relied on it, but Hyrum's law, we don't want to actually exploit this by NOT taking the copy. Converesely, matching over QStringView already requires that the string data is kept alive as long as QRE(Match) objects are alive. Add a doc note to give us the freedom to do the change in Qt 7. [ChangeLog][QtCore][QRegularExpression] QRegularExpression takes a shallow copy of a QString subject when matching over it. This means that users can destroy or modify the string data while still having match results over it. This behavior is deprecated; in a future version of Qt, QRegularExpression will no longer take a copy. Note that behavior has always been undocumented and users were never supposed to modify a subject string while match objects were alive on it. In practice, it's very unlikely that your code is relying on the existing behavior. Change-Id: Ibc5f900c09a007139fb12fc4d7f11e4a8f31bf38 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/text/qregularexpression.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp
index 827884d709..fd0e10dfe6 100644
--- a/src/corelib/text/qregularexpression.cpp
+++ b/src/corelib/text/qregularexpression.cpp
@@ -1571,6 +1571,11 @@ qsizetype QRegularExpression::patternErrorOffset() const
The returned QRegularExpressionMatch object contains the results of the
match.
+ \note The data referenced by \a subject should remain valid as long
+ as there are QRegularExpressionMatch objects using it. At the moment
+ Qt makes a (shallow) copy of the data, but this behavior may change
+ in a future version of Qt.
+
\sa QRegularExpressionMatch, {normal matching}
*/
QRegularExpressionMatch QRegularExpression::match(const QString &subject,
@@ -1628,6 +1633,11 @@ QRegularExpressionMatch QRegularExpression::match(QStringView subjectView,
The returned QRegularExpressionMatchIterator is positioned before the
first match result (if any).
+ \note The data referenced by \a subject should remain valid as long
+ as there are QRegularExpressionMatch objects using it. At the moment
+ Qt makes a (shallow) copy of the data, but this behavior may change
+ in a future version of Qt.
+
\sa QRegularExpressionMatchIterator, {global matching}
*/
QRegularExpressionMatchIterator QRegularExpression::globalMatch(const QString &subject,