diff options
Diffstat (limited to 'docs/checks/README-strict-iterators.md')
-rw-r--r-- | docs/checks/README-strict-iterators.md | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/docs/checks/README-strict-iterators.md b/docs/checks/README-strict-iterators.md new file mode 100644 index 00000000..0730710a --- /dev/null +++ b/docs/checks/README-strict-iterators.md @@ -0,0 +1,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"; + } |