From c358ae18569e41769ec20d1a7e64bcfd1a318316 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 8 Aug 2025 16:14:40 +0200 Subject: [PATCH 1/4] Update checkclass.cpp --- lib/checkclass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(); From 364715da1d76aa29820c1f771d056894c25faf9e Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 8 Aug 2025 16:20:20 +0200 Subject: [PATCH 2/4] Update testclass.cpp --- test/testclass.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/testclass.cpp b/test/testclass.cpp index 2cb62d257f2..d897ffbb936 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 From 0bba69faf191a56d6d1738035bc9b3311e62b99d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 8 Aug 2025 16:36:18 +0200 Subject: [PATCH 3/4] Update testclass.cpp --- test/testclass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testclass.cpp b/test/testclass.cpp index d897ffbb936..529ef33d7a7 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -6823,7 +6823,7 @@ class TestClass : public TestFixture { errout_str()); checkConst("struct S {\n" // #12162 - " bool has(int i) { return m.find(i) != m.end(); }\n"); + " 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", From 53eb2efd4f2d5d7051a934bd1d454ad087f64b7a Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 8 Aug 2025 17:00:28 +0200 Subject: [PATCH 4/4] Update testclass.cpp --- test/testclass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testclass.cpp b/test/testclass.cpp index 529ef33d7a7..a1bd19f9850 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -6826,7 +6826,7 @@ class TestClass : public TestFixture { " 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", + ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::has' can be const. [functionConst]\n", errout_str()); }