Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.2.2
-
None
-
-
ddba24535fb5732c3cb757414cf1a393bd98f693
Description
The operator*() for QJsonArray::const_iterator and QJsonObject::const_iterator is defined as follows:
inline const QJsonValueRef operator*() const { return item; }
Since the const qualifier on the return type by value is irrelevant, this means we can modify a JSON array or object even when it is const. This compiles without warning and modifies the array:
const QJsonArray array = ...; for (auto v : array) v = 0;
I'm not sure how this could be fixed. In Qt 5, this operator*() returned a QJsonValue, so the potential modification was limited to the value v. Of course the fix in the user code could be to write for (const auto v : array) instead.
Attachments
Issue Links
- relates to
-
QTBUG-56221 QJsonValue QJsonObject::operator[](const QString &key) const is a trap
- Reported
-
QTBUG-85700 Chase up deprecations and ### Qt6 comments throughout src/corelib/
- Closed