Summary: | detaching-member: don't warn when non-const method is called on item | ||
---|---|---|---|
Product: | [Developer tools] clazy | Reporter: | Nyall Dawson <nyall.dawson> |
Component: | general | Assignee: | Sergio Martins <smartins> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | smartins |
Priority: | NOR | ||
Version First Reported In: | unspecified | ||
Target Milestone: | --- | ||
Platform: | Other | ||
OS: | Linux | ||
Latest Commit: | http://commits.kde.org/clazy/a85e4e1b9da90970d6270cb2674aa41eb0bbe933 | Version Fixed In: | |
Sentry Crash Report: |
Description
Nyall Dawson
2015-12-14 21:04:39 UTC
the warning is because of [1] no ? yes, but in this case there's no way around calling the detaching [] operator you can use .at(0), which doesn't detach: #include <QVector> #include <QDebug> struct T { void nonConst() { qDebug() << "T::nonConst"; } }; int main() { QVector<T*> vec = {new T()}; vec.at(0)->nonConst(); return 0; } however for values instead of pointers you're correct Yes - that's what I was referring to (values). Sorry, should have made that clearer to begin with! ...And I also just realised my example was very poorly chosen ;) Git commit a85e4e1b9da90970d6270cb2674aa41eb0bbe933 by Sergio Martins. Committed on 15/12/2015 at 11:23. Pushed by smartins into branch 'master'. detaching-member: Fix false positive When calling m_listOfValues[0].nonConstMethod() we can't use .at() M +11 -1 checks/detachingmember.cpp M +1 -1 tests/detaching-member/main.cpp M +1 -1 tests/detaching-member/main.cpp.expected http://commits.kde.org/clazy/a85e4e1b9da90970d6270cb2674aa41eb0bbe933 |