diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 5f98d376a91..df118ce81be 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2147,7 +2147,7 @@ void CheckOtherImpl::checkConstPointer() // continue; if (!isConstPointerVariable(p, mSettings)) continue; - if (p->typeStartToken() && p->typeStartToken()->isSimplifiedTypedef() && !(Token::simpleMatch(p->typeEndToken(), "*") && !p->typeEndToken()->isSimplifiedTypedef())) + if (p->typeStartToken() && p->typeStartToken()->isSimplifiedTypedef() && Token::simpleMatch(p->typeEndToken(), "*") && p->typeEndToken()->isSimplifiedTypedef()) continue; constVariableError(p, p->isArgument() ? p->scope()->function : nullptr, foundAllBaseClasses); } diff --git a/test/cfg/windows.cpp b/test/cfg/windows.cpp index 37c580a0134..689fd425604 100644 --- a/test/cfg/windows.cpp +++ b/test/cfg/windows.cpp @@ -884,7 +884,7 @@ void uninitvar() // cppcheck-suppress uninitvar lstrcat(buf, _T("test")); buf[0] = _T('\0'); - // TODO cppcheck-suppress constVariable + // cppcheck-suppress constVariable TCHAR buf2[2]; // cppcheck-suppress lstrcatCalled // cppcheck-suppress uninitvar diff --git a/test/testother.cpp b/test/testother.cpp index 32a09055d65..a194c297a8b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4249,6 +4249,14 @@ class TestOther : public TestFixture { " return &(u.i);\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("typedef int I;\n" // #15167 + "I f() {\n" + " I a[1] = { 0 };\n" + " return a[0];\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3:7]: (style) Variable 'a' can be declared as const array [constVariable]\n", + errout_str()); } void constParameterCallback() {