Bug 404328 - don't warn about strict iterator mismatch in const function
Summary: don't warn about strict iterator mismatch in const function
Status: RESOLVED FIXED
Alias: None
Product: clazy
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Unassigned bugs mailing-list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-02-14 09:00 UTC by Milian Wolff
Modified: 2019-02-15 18:45 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 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