#7199 SymbolDatabase::validate() should be run in debug mode and print debug messages. In turn correct some test examples with invalid code.

This commit is contained in:
Alexander Mai 2015-12-06 08:14:04 +01:00
parent 5cf923d091
commit 98f2cd021e
5 changed files with 24 additions and 19 deletions

View File

@ -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<const Token*> 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<std::string, const Function *>::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<Function *>(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;
}

View File

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

View File

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

View File

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

View File

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