Bug 367485

Summary: Invalid loop detach warning for function local container
Product: [Developer tools] clazy Reporter: Mathias Hasselmann <mathias.hasselmann>
Component: generalAssignee: Unassigned bugs mailing-list <unassigned-bugs>
Status: RESOLVED FIXED    
Severity: normal CC: smartins
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Mathias Hasselmann 2016-08-18 09:30:28 UTC
Clazy emits wrong detach warnings for known-to-be local containers:

Model::reset()
{
    beginResetModel();

    constexpr int preallocSize = 160;
    QVarLengthArray<RawDataEntry, preallocSize> initialEntries = {
       ...
    };

   m_data.clear();
    for (const auto &entry: initialEntries) // -Wclazy-range-loop]
        m_data.insert(entry.id, entry);

   endResetModel();
}
Comment 1 Mathias Hasselmann 2016-08-18 09:31:14 UTC
"Known to be local containers" - they don't leave scope and are not passed to any external function.
Comment 2 Sergio Martins 2016-08-20 21:18:08 UTC
Git commit 642c2d801b288e0def3517870a57639afe1a5c74 by Sergio Martins.
Committed on 20/08/2016 at 21:07.
Pushed by smartins into branch 'master'.

range-loop: Reduce false positives

If the container is local and is not passed to any function,
lets not warn.

Not closing bug yet, still can be improved.

M  +8    -3    checks/level1/range-loop.cpp
M  +15   -3    tests/range-loop/main.cpp
M  +6    -5    tests/range-loop/main.cpp.expected

http://commits.kde.org/clazy/642c2d801b288e0def3517870a57639afe1a5c74
Comment 3 Sergio Martins 2016-08-21 15:59:06 UTC
Git commit a2cc115a8e5955947e13564fe2ebd6d15667ac1e by Sergio Martins.
Committed on 21/08/2016 at 15:57.
Pushed by smartins into branch 'master'.

range-loop: Don't warn if the container doesn't detach

M  +4    -4    QtUtils.cpp
M  +4    -1    QtUtils.h
M  +3    -3    StmtBodyRange.h
M  +2    -0    Utils.cpp
M  +3    -1    checks/level1/range-loop.cpp
M  +8    -0    tests/range-loop/main.cpp

http://commits.kde.org/clazy/a2cc115a8e5955947e13564fe2ebd6d15667ac1e