From dd927aab9b5e8f3a600219e5988fd42c08a97086 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 3 Aug 2022 19:04:10 +0200 Subject: [PATCH] Fix #11237 checkLibraryNoReturn with unassigned object (#4338) * Handle float values * Fix #11237 checkLibraryNoReturn with unassigned object --- lib/tokenize.cpp | 16 ++++------------ test/testleakautovar.cpp | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 6e92ba225..c73b294b5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7115,22 +7115,14 @@ bool Tokenizer::isScopeNoReturn(const Token *endScopeToken, bool *unknown) const if (unknown) *unknown = !unknownFunc.empty(); if (!unknownFunc.empty() && mSettings->checkLibrary && mSettings->severity.isEnabled(Severity::information)) { - // Is function global? - bool globalFunction = true; + bool warn = true; if (Token::simpleMatch(endScopeToken->tokAt(-2), ") ; }")) { const Token * const ftok = endScopeToken->linkAt(-2)->previous(); - if (ftok && - ftok->isName() && - ftok->function() && - ftok->function()->nestedIn && - ftok->function()->nestedIn->type != Scope::eGlobal) { - globalFunction = false; - } + if (ftok && ftok->type()) // constructor call + warn = false; } - // don't warn for nonglobal functions (class methods, functions hidden in namespaces) since they can't be configured yet - // FIXME: when methods and namespaces can be configured properly, remove the "globalFunction" check - if (globalFunction) { + if (warn) { reportError(endScopeToken->previous(), Severity::information, "checkLibraryNoReturn", diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 6f881e87a..a2d34acf7 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -2406,6 +2406,20 @@ private: " static_assert(1 == sizeof(char), \"test\");\n" "}\n", /*cpp*/ true); ASSERT_EQUALS("", errout.str()); + + check("namespace pal {\n" // #11237 + " struct AutoTimer {};\n" + "}\n" + "int main() {\n" + " pal::AutoTimer();\n" + "}\n", /*cpp*/ true); + ASSERT_EQUALS("", errout.str()); + + check("struct AutoTimer {};\n" + "int main() {\n" + " AutoTimer();\n" + "}\n", /*cpp*/ true); + ASSERT_EQUALS("", errout.str()); } void ptrptr() {