aboutsummaryrefslogtreecommitdiffstats
path: root/src/checks/level0/README-strict-iterators.md
blob: 0730710aaac8ea6fc54e827ee622fc8eb7c955e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# strict-iterators

Warns when `iterator` objects are implicitly cast to `const_iterator`.
This is mostly equivalent to passing -DQT_STRICT_ITERATORS to the compiler.
This prevents detachments but also caches subtle bugs such as:

    QHash<int, int> wrong;
    if (wrong.find(1) == wrong.cend()) {
        qDebug() << "Not found";
    } else {
        qDebug() << "Found"; // find() detached the container before cend() was called, so it prints "Found"
    }

    QHash<int, int> right;
    if (right.constFind(1) == right.cend()) {
        qDebug() << "Not found"; // This is correct now !
    } else {
        qDebug() << "Found";
    }