Skip to content

Commit 831aec5

Browse files
Fix #12185 FN constVariablePointer with stream (#5659)
1 parent e01e090 commit 831aec5

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,7 @@ void CheckOther::checkConstPointer()
15801580
}
15811581
} else {
15821582
int argn = -1;
1583-
if (Token::Match(parent, "%oror%|%comp%|&&|?|!|-"))
1583+
if (Token::Match(parent, "%oror%|%comp%|&&|?|!|-|<<"))
15841584
continue;
15851585
if (Token::simpleMatch(parent, "(") && Token::Match(parent->astOperand1(), "if|while"))
15861586
continue;

test/cfg/opencv2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void ignoredReturnValue()
3939

4040
void memleak()
4141
{
42-
char * pBuf = (char *)cv::fastMalloc(1000); // cppcheck-suppress cstyleCast
42+
const char * pBuf = (char *)cv::fastMalloc(1000); // cppcheck-suppress cstyleCast
4343
std::cout << pBuf;
4444
// cppcheck-suppress memleak
4545
}

test/testother.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3882,6 +3882,13 @@ class TestOther : public TestFixture {
38823882
ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'r' can be declared as pointer to const\n"
38833883
"[test.cpp:1]: (style) Parameter 'b' can be declared as pointer to const\n",
38843884
errout.str());
3885+
3886+
check("void f(int i) {\n" // #12185
3887+
" void* p = &i;\n"
3888+
" std::cout << p << '\\n';\n"
3889+
"}\n");
3890+
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'p' can be declared as pointer to const\n",
3891+
errout.str());
38853892
}
38863893

38873894
void switchRedundantAssignmentTest() {
@@ -8436,7 +8443,7 @@ class TestOther : public TestFixture {
84368443
" ptr = otherPtr;\n"
84378444
" free(otherPtr - xx - 1);\n"
84388445
"}");
8439-
ASSERT_EQUALS("", errout.str());
8446+
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'ptr' can be declared as pointer to const\n", errout.str());
84408447
}
84418448

84428449
void checkRedundantCopy() {

0 commit comments

Comments
 (0)