Fix #11237 checkLibraryNoReturn with unassigned object (#4338)

* Handle float values

* Fix #11237 checkLibraryNoReturn with unassigned object
This commit is contained in:
chrchr-github 2022-08-03 19:04:10 +02:00 committed by GitHub
parent a62c3ea90e
commit dd927aab9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 12 deletions

View File

@ -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",

View File

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