Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.2.2
-
None
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-85700 Chase up deprecations and ### Qt6 comments throughout src/corelib/
- Closed