Skip to content

Commit

Permalink
Fix #12796 FN: (regression) constParameter (array) (danmar#7055)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Dec 4, 2024
1 parent 14f3620 commit 354f0e6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2913,7 +2913,7 @@ static bool isExpressionChangedAt(const F& getExprTok,
bool aliased = false;
// If we can't find the expression then assume it is an alias
auto expr = getExprTok();
if (!expr)
if (!expr && !(tok->valueType() && tok->valueType()->pointer == 0 && tok->valueType()->reference == Reference::None))
aliased = true;
if (!aliased)
aliased = isAliasOf(tok, expr, &i);
Expand Down
10 changes: 10 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4374,6 +4374,16 @@ class TestOther : public TestFixture {
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'a' can be declared as const array\n",
errout_str());

check("void f(int n, int v[42]) {\n" // #12796
" int j = 0;\n"
" for (int i = 0; i < n; ++i) {\n"
" j += 1;\n"
" if (j == 1) {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'v' can be declared as const array\n",
errout_str());
}

void switchRedundantAssignmentTest() {
Expand Down

0 comments on commit 354f0e6

Please sign in to comment.