Skip to content

Commit 98f2cd0

Browse files
committed
danmar#7199 SymbolDatabase::validate() should be run in debug mode and print debug messages. In turn correct some test examples with invalid code.
1 parent 5cf923d commit 98f2cd0

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

lib/symboldatabase.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,11 +1430,19 @@ void SymbolDatabase::validate() const
14301430
const std::size_t functions = functionScopes.size();
14311431
for (std::size_t i = 0; i < functions; ++i) {
14321432
const Scope* scope = functionScopes[i];
1433-
if (scope->isExecutable()) {
1434-
const Function* function = scope->function;
1435-
if (!function) {
1436-
cppcheckError(nullptr);
1433+
const Function* function = scope->function;
1434+
if (scope->isExecutable() && !function) {
1435+
if (_settings->debugwarnings)
1436+
{
1437+
const std::list<const Token*> callstack(1, scope->classDef);
1438+
const std::string msg = std::string("executable scope '") + scope->classDef->str() + "' with unknown function";
1439+
const ErrorLogger::ErrorMessage errmsg(callstack, &_tokenizer->list, Severity::debug,
1440+
"symbolDatabaseWarning",
1441+
msg,
1442+
false);
1443+
_errorLogger->reportErr(errmsg);
14371444
}
1445+
14381446
}
14391447
}
14401448
}
@@ -1687,7 +1695,7 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
16871695

16881696
Function* SymbolDatabase::addGlobalFunction(Scope*& scope, const Token*& tok, const Token *argStart, const Token* funcStart)
16891697
{
1690-
Function* function = 0;
1698+
Function* function = nullptr;
16911699
for (std::multimap<std::string, const Function *>::iterator i = scope->functionMap.find(tok->str()); i != scope->functionMap.end() && i->first == tok->str(); ++i) {
16921700
if (Function::argsMatch(scope, i->second->argDef->next(), argStart->next(), "", 0)) {
16931701
function = const_cast<Function *>(i->second);
@@ -1709,7 +1717,7 @@ Function* SymbolDatabase::addGlobalFunction(Scope*& scope, const Token*& tok, co
17091717
function->functionScope = scope;
17101718
return function;
17111719
}
1712-
return 0;
1720+
return nullptr;
17131721
}
17141722

17151723
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)
20002008
base.isVirtual = true;
20012009
tok2 = tok2->next();
20022010
}
2003-
20042011
if (!tok2)
20052012
return nullptr;
20062013

@@ -2061,7 +2068,7 @@ const Function* Type::getFunction(const std::string& funcName) const
20612068

20622069
for (std::size_t i = 0; i < derivedFrom.size(); i++) {
20632070
if (derivedFrom[i].type) {
2064-
const Function* func = derivedFrom[i].type->getFunction(funcName);
2071+
const Function* const func = derivedFrom[i].type->getFunction(funcName);
20652072
if (func)
20662073
return func;
20672074
}

lib/tokenize.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7540,10 +7540,10 @@ void Tokenizer::simplifyEnum()
75407540
continue;
75417541
}
75427542

7543-
Token * enumName = 0;
7544-
Token * enumValue = 0;
7545-
Token * enumValueStart = 0;
7546-
Token * enumValueEnd = 0;
7543+
Token * enumName = nullptr;
7544+
Token * enumValue = nullptr;
7545+
Token * enumValueStart = nullptr;
7546+
Token * enumValueEnd = nullptr;
75477547

75487548
if (Token::Match(tok1->previous(), ",|{ %type%")) {
75497549
if (Token::Match(tok1->next(), ",|}")) {
@@ -7811,7 +7811,7 @@ void Tokenizer::simplifyEnum()
78117811

78127812
tempTok->insertToken(";");
78137813
tempTok = tempTok->next();
7814-
if (typeTokenStart == 0)
7814+
if (typeTokenStart == nullptr)
78157815
tempTok->insertToken("int");
78167816
else {
78177817
Token *tempTok1 = typeTokenStart;
@@ -9840,9 +9840,7 @@ void Tokenizer::createSymbolDatabase()
98409840
{
98419841
if (!_symbolDatabase)
98429842
_symbolDatabase = new SymbolDatabase(this, _settings, _errorLogger);
9843-
if (_settings->debug) {
9844-
//_symbolDatabase->validate();
9845-
}
9843+
_symbolDatabase->validate();
98469844
}
98479845

98489846
void Tokenizer::deleteSymbolDatabase()

test/testconstructors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2519,7 +2519,7 @@ class TestConstructors : public TestFixture {
25192519
" float g;\n"
25202520
"public:\n"
25212521
" Fred() : f{0, true} { }\n"
2522-
" float get() const\n"
2522+
" float get() const;\n"
25232523
"};\n"
25242524
"float Fred::get() const { return g; }");
25252525
ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable 'Fred::g' is not initialized in the constructor.\n", errout.str());

test/testother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4992,7 +4992,7 @@ class TestOther : public TestFixture {
49924992
check("class C {\n"
49934993
" int x;\n"
49944994
" void g() { return x*x; }\n"
4995-
" void f();\n"
4995+
" void f(Foo z);\n"
49964996
"};\n"
49974997
"\n"
49984998
"void C::f(Foo z) {\n"

test/testsymboldatabase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ class TestSymbolDatabase: public TestFixture {
15981598
check("testing::testing()\n"
15991599
"{\n"
16001600
"}");
1601-
ASSERT_EQUALS("", errout.str());
1601+
ASSERT_EQUALS("[test.cpp:1]: (debug) executable scope 'testing' with unknown function\n", errout.str());
16021602
}
16031603

16041604
void symboldatabase5() {

0 commit comments

Comments
 (0)