Bug 361489

Summary: qdeleteall: Do not warn on qDeleteAll(some_hash.values(some_key))
Product: [Developer tools] clazy Reporter: Richard <richard.oehlinger>
Component: generalAssignee: Sergio Martins <smartins>
Status: RESOLVED FIXED    
Severity: normal CC: smartins
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Fedora RPMs   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Richard 2016-04-07 09:23:32 UTC
I think the check should not warn and it should definitely not propose the wrong fix on code like this.
QHash <int, MyClass*> some_hash;
//...
qDeleteAll(some_hash.values(some_key))
Just the call without arguments should be flaged: qDeleteAll(some_hash.values())

Reproducible: Always
Comment 1 Sergio Martins 2016-04-07 12:10:09 UTC
I'll fix the warning message but not remove it.

hash.values(key), just like hash.values() will malloc to create a temporary list

hash.values(key) is a bit more cumbersome for you to fix though, you'd have to write a for loop.
So I've added QHash::equal_range(key), which will be available in Qt 5.7.
Comment 2 Sergio Martins 2016-04-08 16:34:27 UTC
Git commit 53963579d6cc4410cb414302b23772837d8577e1 by Sergio Martins.
Committed on 08/04/2016 at 16:33.
Pushed by smartins into branch 'master'.

qdeleteall: Fix warning when using the values(key) overload

M  +6    -1    checks/qdeleteall.cpp
M  +2    -0    tests/qdeleteall/main.cpp
M  +1    -0    tests/qdeleteall/main.cpp.expected

http://commits.kde.org/clazy/53963579d6cc4410cb414302b23772837d8577e1