Qt-StrictIterators

Warns when iterator objects are implicitly cast to const_iterator

Required inputs: IR

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 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 right;
        if (right.constFind(1) == right.cend()) {
        qDebug() << "Not found"; // This is correct now !
        } else {
        qDebug() << "Found";
        }

This rule is based on clazy rule strict-iterators

Possible Messages

Key

Text

Severity

Disabled

bad_mix

Mixing iterators with const_iterators.

None

False

Options

level

level : int = 0

Importance level of the rule as given for clazy. 0 is most desirable, higher values fall off in quality.