Bug 356699 - detaching-member: don't warn when non-const method is called on item
Summary: detaching-member: don't warn when non-const method is called on item
Status: RESOLVED FIXED
Alias: None
Product: clazy
Classification: Developer tools
Component: general (other bugs)
Version First Reported In: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Sergio Martins
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-14 21:04 UTC by Nyall Dawson
Modified: 2015-12-15 11:24 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nyall Dawson 2015-12-14 21:04:39 UTC
Currently clazy throws an incorrect warning with the detaching-member test when a non-const method is called. For instance,

list[1]->someNonConstMethod();

is incorrectly throwing the detach warning.
Comment 1 Sergio Martins 2015-12-14 21:34:16 UTC
the warning is because of [1] no ?
Comment 2 Nyall Dawson 2015-12-14 21:46:09 UTC
yes, but in this case there's no way around calling the detaching [] operator
Comment 3 Sergio Martins 2015-12-14 22:51:45 UTC
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;
}
Comment 4 Sergio Martins 2015-12-14 23:02:27 UTC
however for values instead of pointers you're correct
Comment 5 Nyall Dawson 2015-12-14 23:12:29 UTC
Yes - that's what I was referring to (values). Sorry, should have made that clearer to begin with!
Comment 6 Nyall Dawson 2015-12-14 23:13:08 UTC
...And I also just realised my example was very poorly chosen ;)
Comment 7 Sergio Martins 2015-12-15 11:24:49 UTC
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