Skip to content

Commit 4aa87ff

Browse files
Partial fix for #12162 false negative: functionConst (#7729)
1 parent d816219 commit 4aa87ff

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/checkclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2596,7 +2596,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, Member
25962596
if (!vt || !vt->container)
25972597
return false;
25982598
const auto yield = vt->container->getYield(end->str());
2599-
if (yield == Library::Container::Yield::START_ITERATOR || yield == Library::Container::Yield::END_ITERATOR) {
2599+
if (contains({Library::Container::Yield::START_ITERATOR, Library::Container::Yield::END_ITERATOR, Library::Container::Yield::ITERATOR}, yield)) {
26002600
const Token* parent = tok1->astParent();
26012601
while (Token::Match(parent, "(|.|::"))
26022602
parent = parent->astParent();

test/testclass.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6821,6 +6821,13 @@ class TestClass : public TestFixture {
68216821
"};\n");
68226822
ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'D::f' can be const. [functionConst]\n",
68236823
errout_str());
6824+
6825+
checkConst("struct S {\n" // #12162
6826+
" bool has(int i) { return m.find(i) != m.end(); }\n"
6827+
" std::map<int, int> m;\n"
6828+
"};\n");
6829+
ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::has' can be const. [functionConst]\n",
6830+
errout_str());
68246831
}
68256832

68266833
void const98() { // #13642

0 commit comments

Comments
 (0)