Bug 404328

Summary: don't warn about strict iterator mismatch in const function
Product: [Developer tools] clazy Reporter: Milian Wolff <mail>
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 Milian Wolff 2019-02-14 09:00:07 UTC
struct Bar {
    bool foo() const
    {
        return mFooIt != mFoo();
    }
    QVector<int> mFoo;
    QVector<int>::iterator mFooIt;
};

clazy reports:
=> Mixing iterators with const_iterators

while technically correct, it's quite useless I think. This code works fine and is safe - maybe the comparison should check whether `const Foo::iterator` and `Foo::const_iterator` are compared, and if so don't emit the warning? 

clazy version: 1.5
clang version: 7.0.1
Comment 1 Milian Wolff 2019-02-14 09:05:21 UTC
even adding an explicit static_cast<> to const_iterator warns:

 warning: Mixing iterators with const_iterators [-Wclazy-strict-iterators]
    return static_cast<decltype(mFoo)::const_iterator>(mFooIt) != mFoo.end();
Comment 2 Sergio Martins 2019-02-15 18:45:57 UTC
Git commit 145e7b6578e690f1aacc250e0cadb8fcfdbb281e by Sergio Martins.
Committed on 15/02/2019 at 18:45.
Pushed by smartins into branch 'master'.

strict-iterators: Don't warn when comparing against an iterator member var

It won't detach the container

M  +17   -0    src/checks/level0/strict-iterators.cpp
M  +11   -0    tests/strict-iterators/main.cpp

https://commits.kde.org/clazy/145e7b6578e690f1aacc250e0cadb8fcfdbb281e