From f53793c413ab6a431c6ce05e3ce5fcdc693e1eba Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 23 Feb 2022 09:12:14 +0100 Subject: [PATCH] Fix #10823 FP cstyleCast with function pointer and calling convention (#3853) --- lib/checkother.cpp | 2 ++ test/testother.cpp | 6 ++++++ 2 files changed, 8 insertions(+) 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__)