Fix #12185 FN constVariablePointer with stream (#5659)

This commit is contained in:
chrchr-github 2023-11-16 17:43:20 +01:00 committed by GitHub
parent e01e090f1c
commit 831aec5c03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 3 deletions

View File

@ -1580,7 +1580,7 @@ void CheckOther::checkConstPointer()
}
} else {
int argn = -1;
if (Token::Match(parent, "%oror%|%comp%|&&|?|!|-"))
if (Token::Match(parent, "%oror%|%comp%|&&|?|!|-|<<"))
continue;
if (Token::simpleMatch(parent, "(") && Token::Match(parent->astOperand1(), "if|while"))
continue;

View File

@ -39,7 +39,7 @@ void ignoredReturnValue()
void memleak()
{
char * pBuf = (char *)cv::fastMalloc(1000); // cppcheck-suppress cstyleCast
const char * pBuf = (char *)cv::fastMalloc(1000); // cppcheck-suppress cstyleCast
std::cout << pBuf;
// cppcheck-suppress memleak
}

View File

@ -3882,6 +3882,13 @@ private:
ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'r' can be declared as pointer to const\n"
"[test.cpp:1]: (style) Parameter 'b' can be declared as pointer to const\n",
errout.str());
check("void f(int i) {\n" // #12185
" void* p = &i;\n"
" std::cout << p << '\\n';\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'p' can be declared as pointer to const\n",
errout.str());
}
void switchRedundantAssignmentTest() {
@ -8436,7 +8443,7 @@ private:
" ptr = otherPtr;\n"
" free(otherPtr - xx - 1);\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'ptr' can be declared as pointer to const\n", errout.str());
}
void checkRedundantCopy() {