#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:
parent
5cf923d091
commit
98f2cd021e
|
@ -1430,11 +1430,19 @@ void SymbolDatabase::validate() const
|
||||||
const std::size_t functions = functionScopes.size();
|
const std::size_t functions = functionScopes.size();
|
||||||
for (std::size_t i = 0; i < functions; ++i) {
|
for (std::size_t i = 0; i < functions; ++i) {
|
||||||
const Scope* scope = functionScopes[i];
|
const Scope* scope = functionScopes[i];
|
||||||
if (scope->isExecutable()) {
|
|
||||||
const Function* function = scope->function;
|
const Function* function = scope->function;
|
||||||
if (!function) {
|
if (scope->isExecutable() && !function) {
|
||||||
cppcheckError(nullptr);
|
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* 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) {
|
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)) {
|
if (Function::argsMatch(scope, i->second->argDef->next(), argStart->next(), "", 0)) {
|
||||||
function = const_cast<Function *>(i->second);
|
function = const_cast<Function *>(i->second);
|
||||||
|
@ -1709,7 +1717,7 @@ Function* SymbolDatabase::addGlobalFunction(Scope*& scope, const Token*& tok, co
|
||||||
function->functionScope = scope;
|
function->functionScope = scope;
|
||||||
return function;
|
return function;
|
||||||
}
|
}
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Function* SymbolDatabase::addGlobalFunctionDecl(Scope*& scope, const Token *tok, const Token *argStart, const Token* funcStart)
|
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;
|
base.isVirtual = true;
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tok2)
|
if (!tok2)
|
||||||
return nullptr;
|
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++) {
|
for (std::size_t i = 0; i < derivedFrom.size(); i++) {
|
||||||
if (derivedFrom[i].type) {
|
if (derivedFrom[i].type) {
|
||||||
const Function* func = derivedFrom[i].type->getFunction(funcName);
|
const Function* const func = derivedFrom[i].type->getFunction(funcName);
|
||||||
if (func)
|
if (func)
|
||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7540,10 +7540,10 @@ void Tokenizer::simplifyEnum()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Token * enumName = 0;
|
Token * enumName = nullptr;
|
||||||
Token * enumValue = 0;
|
Token * enumValue = nullptr;
|
||||||
Token * enumValueStart = 0;
|
Token * enumValueStart = nullptr;
|
||||||
Token * enumValueEnd = 0;
|
Token * enumValueEnd = nullptr;
|
||||||
|
|
||||||
if (Token::Match(tok1->previous(), ",|{ %type%")) {
|
if (Token::Match(tok1->previous(), ",|{ %type%")) {
|
||||||
if (Token::Match(tok1->next(), ",|}")) {
|
if (Token::Match(tok1->next(), ",|}")) {
|
||||||
|
@ -7811,7 +7811,7 @@ void Tokenizer::simplifyEnum()
|
||||||
|
|
||||||
tempTok->insertToken(";");
|
tempTok->insertToken(";");
|
||||||
tempTok = tempTok->next();
|
tempTok = tempTok->next();
|
||||||
if (typeTokenStart == 0)
|
if (typeTokenStart == nullptr)
|
||||||
tempTok->insertToken("int");
|
tempTok->insertToken("int");
|
||||||
else {
|
else {
|
||||||
Token *tempTok1 = typeTokenStart;
|
Token *tempTok1 = typeTokenStart;
|
||||||
|
@ -9840,9 +9840,7 @@ void Tokenizer::createSymbolDatabase()
|
||||||
{
|
{
|
||||||
if (!_symbolDatabase)
|
if (!_symbolDatabase)
|
||||||
_symbolDatabase = new SymbolDatabase(this, _settings, _errorLogger);
|
_symbolDatabase = new SymbolDatabase(this, _settings, _errorLogger);
|
||||||
if (_settings->debug) {
|
_symbolDatabase->validate();
|
||||||
//_symbolDatabase->validate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tokenizer::deleteSymbolDatabase()
|
void Tokenizer::deleteSymbolDatabase()
|
||||||
|
|
|
@ -2519,7 +2519,7 @@ private:
|
||||||
" float g;\n"
|
" float g;\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" Fred() : f{0, true} { }\n"
|
" Fred() : f{0, true} { }\n"
|
||||||
" float get() const\n"
|
" float get() const;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"float Fred::get() const { return g; }");
|
"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());
|
ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable 'Fred::g' is not initialized in the constructor.\n", errout.str());
|
||||||
|
|
|
@ -4992,7 +4992,7 @@ private:
|
||||||
check("class C {\n"
|
check("class C {\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
" void g() { return x*x; }\n"
|
" void g() { return x*x; }\n"
|
||||||
" void f();\n"
|
" void f(Foo z);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"\n"
|
"\n"
|
||||||
"void C::f(Foo z) {\n"
|
"void C::f(Foo z) {\n"
|
||||||
|
|
|
@ -1598,7 +1598,7 @@ private:
|
||||||
check("testing::testing()\n"
|
check("testing::testing()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("[test.cpp:1]: (debug) executable scope 'testing' with unknown function\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void symboldatabase5() {
|
void symboldatabase5() {
|
||||||
|
|
Loading…
Reference in New Issue