diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 783cd47ab..a8a2df548 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -304,6 +304,8 @@ void CheckOther::warningOldStylePointerCast() // Old style pointer casting.. if (!Token::Match(tok, "( const|volatile| const|volatile|class|struct| %type% * const|&| ) (| %name%|%num%|%bool%|%char%|%str%")) continue; + if (Token::Match(tok->previous(), "%type%")) + continue; // skip first "const" in "const Type* const" while (Token::Match(tok->next(), "const|volatile|class|struct")) diff --git a/test/testother.cpp b/test/testother.cpp index 8609ee72d..cec87da46 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1503,6 +1503,12 @@ private: ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n" "[test.cpp:5]: (style) C-style pointer casting\n", errout.str()); + + // #10823 + checkOldStylePointerCast("void f(void* p) {\n" + " auto h = reinterpret_cast(p);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } #define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)