A check for use of [] on non-const containers when the value isn't being modified would be handy - this could also potentially avoid a detach of the container.
I was thinking of a more general check, that included other methods, like first(), last() etc.
commit 6c32f836d79cee3b1716d3e99ae185ad55df877f Author: Sergio Martins <smartins@kde.org> Date: Thu Oct 22 18:59:19 2015 +0100 WIP: Introducing detaching-members check Lots of improvements can be done, for example: container[0] = ..; // This detachment is unavoidable and desired, yet we are emitting a warning
Git commit a8f25a126b8405884557d8d82dff4c586d176e3f by Sergio Martins. Committed on 01/11/2015 at 19:58. Pushed by smartins into branch 'master'. detaching-member: Fix a bunch of false-positives such as: a[0] = "foo"; These kind of detachments are fine and unavoidable M +26 -1 checks/detachingmember.cpp M +11 -0 tests/detaching-member/main.cpp M +1 -0 tests/detaching-member/test.expected http://commits.kde.org/clazy/a8f25a126b8405884557d8d82dff4c586d176e3f
Seems to be working nicely for member variables. For local variables it's a bit more difficult, since most cases will be false-positives, so I won't work on that. Feel free to try, if it has a low rate of false-positives it can be accepted into clazy