diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 51c5f33da..ca7b39f23 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1430,11 +1430,19 @@ void SymbolDatabase::validate() const const std::size_t functions = functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope* scope = functionScopes[i]; - if (scope->isExecutable()) { - const Function* function = scope->function; - if (!function) { - cppcheckError(nullptr); + const Function* function = scope->function; + if (scope->isExecutable() && !function) { + if (_settings->debugwarnings) + { + const std::list callstack(1, scope->classDef); + const std::string msg = std::string("executable scope '") + scope->classDef->str() + "' with unknown function"; + const ErrorLogger::ErrorMessage errmsg(callstack, &_tokenizer->list, Severity::debug, + "symbolDatabaseWarning", + msg, + false); + _errorLogger->reportErr(errmsg); } + } } } @@ -1687,7 +1695,7 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se Function* SymbolDatabase::addGlobalFunction(Scope*& scope, const Token*& tok, const Token *argStart, const Token* funcStart) { - Function* function = 0; + Function* function = nullptr; for (std::multimap::iterator i = scope->functionMap.find(tok->str()); i != scope->functionMap.end() && i->first == tok->str(); ++i) { if (Function::argsMatch(scope, i->second->argDef->next(), argStart->next(), "", 0)) { function = const_cast(i->second); @@ -1709,7 +1717,7 @@ Function* SymbolDatabase::addGlobalFunction(Scope*& scope, const Token*& tok, co function->functionScope = scope; return function; } - return 0; + return nullptr; } Function* SymbolDatabase::addGlobalFunctionDecl(Scope*& scope, const Token *tok, const Token *argStart, const Token* funcStart) @@ -2000,7 +2008,6 @@ const Token *Type::initBaseInfo(const Token *tok, const Token *tok1) base.isVirtual = true; tok2 = tok2->next(); } - if (!tok2) return nullptr; @@ -2061,7 +2068,7 @@ const Function* Type::getFunction(const std::string& funcName) const for (std::size_t i = 0; i < derivedFrom.size(); i++) { if (derivedFrom[i].type) { - const Function* func = derivedFrom[i].type->getFunction(funcName); + const Function* const func = derivedFrom[i].type->getFunction(funcName); if (func) return func; } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c576659f1..2b2436fce 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7540,10 +7540,10 @@ void Tokenizer::simplifyEnum() continue; } - Token * enumName = 0; - Token * enumValue = 0; - Token * enumValueStart = 0; - Token * enumValueEnd = 0; + Token * enumName = nullptr; + Token * enumValue = nullptr; + Token * enumValueStart = nullptr; + Token * enumValueEnd = nullptr; if (Token::Match(tok1->previous(), ",|{ %type%")) { if (Token::Match(tok1->next(), ",|}")) { @@ -7811,7 +7811,7 @@ void Tokenizer::simplifyEnum() tempTok->insertToken(";"); tempTok = tempTok->next(); - if (typeTokenStart == 0) + if (typeTokenStart == nullptr) tempTok->insertToken("int"); else { Token *tempTok1 = typeTokenStart; @@ -9840,9 +9840,7 @@ void Tokenizer::createSymbolDatabase() { if (!_symbolDatabase) _symbolDatabase = new SymbolDatabase(this, _settings, _errorLogger); - if (_settings->debug) { - //_symbolDatabase->validate(); - } + _symbolDatabase->validate(); } void Tokenizer::deleteSymbolDatabase() diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index a55cdf22b..ddba1633c 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -2519,7 +2519,7 @@ private: " float g;\n" "public:\n" " Fred() : f{0, true} { }\n" - " float get() const\n" + " float get() const;\n" "};\n" "float Fred::get() const { return g; }"); ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable 'Fred::g' is not initialized in the constructor.\n", errout.str()); diff --git a/test/testother.cpp b/test/testother.cpp index f4c38037d..bfb8ae651 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4992,7 +4992,7 @@ private: check("class C {\n" " int x;\n" " void g() { return x*x; }\n" - " void f();\n" + " void f(Foo z);\n" "};\n" "\n" "void C::f(Foo z) {\n" diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index d815d7dfa..db4a2c1e0 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -1598,7 +1598,7 @@ private: check("testing::testing()\n" "{\n" "}"); - ASSERT_EQUALS("", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (debug) executable scope 'testing' with unknown function\n", errout.str()); } void symboldatabase5() {