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() {