mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-01 05:08:05 -06:00
Don't implicitly cast iterator to const_iterator
It prevents detachments:
To illustrate:
QMap<QString, QString> map;
/* code compiles and works fine but find() returns the non-const
QMap::iterator that detaches!
*/
QMap<QString, QString>::const_iterator it = map.find("girish");
but also some subtle bugs:
QHash<int, int> wrong;
if (wrong.find(1) == wrong.cend()) {
qDebug() << "Not found";
} else {
/* find() detached the container before cend() was called, so it
prints "Found"
*/
qDebug() << "Found";
}
QHash<int, int> right;
if (right.constFind(1) == right.cend()) {
qDebug() << "Not found"; // This is correct now !
} else {
qDebug() << "Found";
}
Enforced by QT_STRICT_ITERATORS definition.
This commit is contained in:
@@ -57,6 +57,7 @@ include(../version.pri)
|
||||
DEFINES += QT_NO_CAST_TO_ASCII
|
||||
# Efficient construction for QString & QByteArray (Qt >= 4.8)
|
||||
DEFINES += QT_USE_QSTRINGBUILDER
|
||||
DEFINES += QT_STRICT_ITERATORS
|
||||
|
||||
INCLUDEPATH += $$PWD
|
||||
|
||||
|
||||
Reference in New Issue
Block a user