Skip to content

Commit 717566c

Browse files
Partial fix for #14810 FN constVariablePointer (cbegin() called on container) (#8619)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent c903d68 commit 717566c

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

lib/library.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,6 +1781,8 @@ bool Library::isFunctionConst(const Token *ftok) const
17811781
const Yield yield = astContainerYield(ftok->astParent()->astOperand1(), *this);
17821782
if (yield == Yield::EMPTY || yield == Yield::SIZE || yield == Yield::BUFFER_NT)
17831783
return true;
1784+
if ((yield == Yield::START_ITERATOR || yield == Yield::END_ITERATOR) && ftok->str()[0] == 'c')
1785+
return true;
17841786
}
17851787
return false;
17861788
}

test/testother.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4867,6 +4867,11 @@ class TestOther : public TestFixture {
48674867
ASSERT_EQUALS("[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n"
48684868
"[test.cpp:1:20]: (style) Parameter 'q' can be declared as pointer to const [constParameterPointer]\n",
48694869
errout_str());
4870+
4871+
check("int f(std::vector<int>* p) {\n" // #14810
4872+
" return *p->cbegin();\n"
4873+
"}\n");
4874+
ASSERT_EQUALS("[test.cpp:1:25]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str());
48704875
}
48714876

48724877
void constArray() {

0 commit comments

Comments
 (0)