From 8a0acf80003c889bbf4ab277e5c472cf7c67611b Mon Sep 17 00:00:00 2001 From: chrchr Date: Fri, 16 Feb 2024 12:03:25 +0100 Subject: [PATCH] Skip template arguments --- lib/checkother.cpp | 5 ++++- test/testother.cpp | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index e803adb59f8..8eaea623500 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -316,8 +316,11 @@ void CheckOther::warningOldStylePointerCast() if (tok->str() != "(") continue; const Token* castTok = tok->next(); - while (Token::Match(castTok, "const|volatile|class|struct|union|%type%|::")) + while (Token::Match(castTok, "const|volatile|class|struct|union|%type%|::")) { castTok = castTok->next(); + if (Token::simpleMatch(castTok, "<") && castTok->link()) + castTok = castTok->link()->next(); + } if (castTok == tok->next() || !Token::simpleMatch(castTok, "*")) continue; while (Token::Match(castTok, "*|const|&")) diff --git a/test/testother.cpp b/test/testother.cpp index 2904c480234..3f938af2e85 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1905,9 +1905,11 @@ class TestOther : public TestFixture { "void f(void* p) {\n" " auto ps = (N::S*)p;\n" " auto pu = (union U*)p;\n" + " auto pv = (std::vector*)(p);\n" "}\n"); ASSERT_EQUALS("[test.cpp:7]: (style) C-style pointer casting\n" - "[test.cpp:8]: (style) C-style pointer casting\n", + "[test.cpp:8]: (style) C-style pointer casting\n" + "[test.cpp:9]: (style) C-style pointer casting\n", errout.str()); }