Skip to content

Commit 1527922

Browse files
Fix #13072 FN constVariablePointer for nested array access (regression) (#6773)
1 parent e3a5d41 commit 1527922

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1658,7 +1658,7 @@ void CheckOther::checkConstPointer()
16581658
continue;
16591659
if (deref != NONE) {
16601660
const Token* gparent = parent->astParent();
1661-
while (Token::simpleMatch(gparent, "[") && parent->str() == gparent->str())
1661+
while (Token::simpleMatch(gparent, "[") && parent != gparent->astOperand2() && parent->str() == gparent->str())
16621662
gparent = gparent->astParent();
16631663
if (deref == MEMBER) {
16641664
if (!gparent)

test/testother.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4193,6 +4193,12 @@ class TestOther : public TestFixture {
41934193
"}\n");
41944194
ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 's' can be declared as pointer to const\n",
41954195
errout_str());
4196+
4197+
check("void f(int* a, int* b, int i) {\n" // #13072
4198+
" a[b[i]] = 0;\n"
4199+
"}\n");
4200+
ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'b' can be declared as pointer to const\n",
4201+
errout_str());
41964202
}
41974203

41984204
void constArray() {

0 commit comments

Comments
 (0)