Skip to content

Commit 1e40a2e

Browse files
Fix #5210 C-style pointer casting not detected for casts to ** (#4075)
1 parent 509e42a commit 1e40a2e

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ void CheckOther::warningOldStylePointerCast()
301301
tok = scope->bodyStart;
302302
for (; tok && tok != scope->bodyEnd; tok = tok->next()) {
303303
// Old style pointer casting..
304-
if (!Token::Match(tok, "( const|volatile| const|volatile|class|struct| %type% * const|&| ) (| %name%|%num%|%bool%|%char%|%str%"))
304+
if (!Token::Match(tok, "( const|volatile| const|volatile|class|struct| %type% * *| *| const|&| ) (| %name%|%num%|%bool%|%char%|%str%"))
305305
continue;
306306
if (Token::Match(tok->previous(), "%type%"))
307307
continue;

test/testother.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,15 @@ class TestOther : public TestFixture {
15671567
" auto h = reinterpret_cast<void (STDAPICALLTYPE*)(int)>(p);\n"
15681568
"}\n");
15691569
ASSERT_EQUALS("", errout.str());
1570+
1571+
// #5210
1572+
checkOldStylePointerCast("void f(void* v1, void* v2) {\n"
1573+
" T** p1 = (T**)v1;\n"
1574+
" T*** p2 = (T***)v2;\n"
1575+
"}\n");
1576+
ASSERT_EQUALS("[test.cpp:2]: (style) C-style pointer casting\n"
1577+
"[test.cpp:3]: (style) C-style pointer casting\n",
1578+
errout.str());
15701579
}
15711580

15721581
#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)

0 commit comments

Comments
 (0)