diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index d5621371083..3c7816a9479 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2596,7 +2596,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, Member if (!vt || !vt->container) return false; const auto yield = vt->container->getYield(end->str()); - if (yield == Library::Container::Yield::START_ITERATOR || yield == Library::Container::Yield::END_ITERATOR) { + if (contains({Library::Container::Yield::START_ITERATOR, Library::Container::Yield::END_ITERATOR, Library::Container::Yield::ITERATOR}, yield)) { const Token* parent = tok1->astParent(); while (Token::Match(parent, "(|.|::")) parent = parent->astParent(); diff --git a/test/testclass.cpp b/test/testclass.cpp index 2cb62d257f2..a1bd19f9850 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -6821,6 +6821,13 @@ class TestClass : public TestFixture { "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'D::f' can be const. [functionConst]\n", errout_str()); + + checkConst("struct S {\n" // #12162 + " bool has(int i) { return m.find(i) != m.end(); }\n" + " std::map m;\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::has' can be const. [functionConst]\n", + errout_str()); } void const98() { // #13642