From 457e0ce0c812200f457a367b3b27c4e8247fcca7 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Tue, 13 Jun 2023 21:48:16 +0200 Subject: [PATCH] Partial fix for #11189 checkLibraryNoReturn with std::function parameter --- lib/tokenize.cpp | 2 +- test/testleakautovar.cpp | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b0fc121dd..4f76e272a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7772,7 +7772,7 @@ bool Tokenizer::isScopeNoReturn(const Token *endScopeToken, bool *unknown) const bool warn = true; if (Token::simpleMatch(endScopeToken->tokAt(-2), ") ; }")) { const Token * const ftok = endScopeToken->linkAt(-2)->previous(); - if (ftok && (ftok->type() || ftok->function())) // constructor call + if (ftok && (ftok->type() || ftok->function() || ftok->variable())) // constructor call warn = false; } diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 82da49a40..1ddcf20bf 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -2652,12 +2652,20 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Resource leak: file\n", errout.str()); } - void configuration6() { // #11198 - check("void f() {}\n" + void configuration6() { + check("void f() {}\n" // #11198 "void g() {\n" " f();\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void f(std::function cb) {\n" // #11189 + " cb();\n" + "}\n" + "void g(void (*cb)()) {\n" + " cb();\n" + "}\n", /*cpp*/ true); + ASSERT_EQUALS("", errout.str()); } void ptrptr() {