Skip to content

Commit c09ccdb

Browse files
Fix #15167 FN constVariable with typedef (#8990)
1 parent 189de72 commit c09ccdb

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎lib/checkother.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,7 @@ void CheckOtherImpl::checkConstPointer()
21472147
// continue;
21482148
if (!isConstPointerVariable(p, mSettings))
21492149
continue;
2150-
if (p->typeStartToken() && p->typeStartToken()->isSimplifiedTypedef() && !(Token::simpleMatch(p->typeEndToken(), "*") && !p->typeEndToken()->isSimplifiedTypedef()))
2150+
if (p->typeStartToken() && p->typeStartToken()->isSimplifiedTypedef() && Token::simpleMatch(p->typeEndToken(), "*") && p->typeEndToken()->isSimplifiedTypedef())
21512151
continue;
21522152
constVariableError(p, p->isArgument() ? p->scope()->function : nullptr, foundAllBaseClasses);
21532153
}

‎test/cfg/windows.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ void uninitvar()
884884
// cppcheck-suppress uninitvar
885885
lstrcat(buf, _T("test"));
886886
buf[0] = _T('\0');
887-
// TODO cppcheck-suppress constVariable
887+
// cppcheck-suppress constVariable
888888
TCHAR buf2[2];
889889
// cppcheck-suppress lstrcatCalled
890890
// cppcheck-suppress uninitvar

‎test/testother.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4249,6 +4249,14 @@ class TestOther : public TestFixture {
42494249
" return &(u.i);\n"
42504250
"}\n");
42514251
ASSERT_EQUALS("", errout_str());
4252+
4253+
check("typedef int I;\n" // #15167
4254+
"I f() {\n"
4255+
" I a[1] = { 0 };\n"
4256+
" return a[0];\n"
4257+
"}\n");
4258+
ASSERT_EQUALS("[test.cpp:3:7]: (style) Variable 'a' can be declared as const array [constVariable]\n",
4259+
errout_str());
42524260
}
42534261

42544262
void constParameterCallback() {

0 commit comments

Comments
 (0)