Skip to content

Commit 354f0e6

Browse files
Fix #12796 FN: (regression) constParameter (array) (#7055)
1 parent 14f3620 commit 354f0e6

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/astutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2913,7 +2913,7 @@ static bool isExpressionChangedAt(const F& getExprTok,
29132913
bool aliased = false;
29142914
// If we can't find the expression then assume it is an alias
29152915
auto expr = getExprTok();
2916-
if (!expr)
2916+
if (!expr && !(tok->valueType() && tok->valueType()->pointer == 0 && tok->valueType()->reference == Reference::None))
29172917
aliased = true;
29182918
if (!aliased)
29192919
aliased = isAliasOf(tok, expr, &i);

test/testother.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4374,6 +4374,16 @@ class TestOther : public TestFixture {
43744374
"}\n");
43754375
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'a' can be declared as const array\n",
43764376
errout_str());
4377+
4378+
check("void f(int n, int v[42]) {\n" // #12796
4379+
" int j = 0;\n"
4380+
" for (int i = 0; i < n; ++i) {\n"
4381+
" j += 1;\n"
4382+
" if (j == 1) {}\n"
4383+
" }\n"
4384+
"}\n");
4385+
ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'v' can be declared as const array\n",
4386+
errout_str());
43774387
}
43784388

43794389
void switchRedundantAssignmentTest() {

0 commit comments

Comments
 (0)