Destructor detected as constructor resulting in false variable not initialized warnings

This commit is contained in:
Robert Reif 2015-01-12 06:11:22 +01:00 committed by Daniel Marjamäki
parent 910af75e3a
commit 68bb197bcb
3 changed files with 42 additions and 1 deletions

View File

@ -3451,10 +3451,13 @@ const Scope * SymbolDatabase::findNamespace(const Token * tok, const Scope * sco
Function * SymbolDatabase::findFunctionInScope(const Token *func, const Scope *ns)
{
const Function * function = nullptr;
const bool destructor = func->strAt(-1) == "~";
for (std::multimap<std::string, const Function *>::const_iterator it = ns->functionMap.find(func->str());
it != ns->functionMap.end() && it->first == func->str(); ++it) {
if (Function::argsMatch(ns, func->tokAt(2), it->second->argDef->next(), "", 0)) {
if (Function::argsMatch(ns, func->tokAt(2), it->second->argDef->next(), "", 0) &&
it->second->isDestructor() == destructor) {
function = it->second;
break;
}

View File

@ -137,6 +137,7 @@ private:
TEST_CASE(uninitVar27); // ticket #5170 - rtl::math::setNan(&d)
TEST_CASE(uninitVar28); // ticket #6258
TEST_CASE(uninitVar29);
TEST_CASE(uninitVar30); // ticket #6417
TEST_CASE(uninitVarEnum);
TEST_CASE(uninitVarStream);
TEST_CASE(uninitVarTypedef);
@ -2160,6 +2161,22 @@ private:
"[test.cpp:25]: (warning) Member variable 'D::i' is not initialized in the constructor.\n", errout.str());
}
void uninitVar30() { // ticket #6417
check("namespace NS {\n"
" class MyClass {\n"
" public:\n"
" MyClass();\n"
" ~MyClass();\n"
" private:\n"
" bool SomeVar;\n"
" };\n"
"}\n"
"using namespace NS;\n"
"MyClass::~MyClass() { }\n"
"MyClass::MyClass() : SomeVar(false) { }\n");
ASSERT_EQUALS("", errout.str());
}
void uninitVarArray1() {
check("class John\n"
"{\n"

View File

@ -221,6 +221,7 @@ private:
TEST_CASE(symboldatabase45); // #6125
TEST_CASE(symboldatabase46); // #6171 (anonymous namespace)
TEST_CASE(symboldatabase47); // #6308
TEST_CASE(symboldatabase48); // #6417
TEST_CASE(isImplicitlyVirtual);
@ -2044,6 +2045,26 @@ private:
ASSERT(db && !db->functionScopes.empty() && db->functionScopes.front()->function && db->functionScopes.front()->function->functionScope == db->functionScopes.front());
}
void symboldatabase48() { // #6417
GET_SYMBOL_DB("namespace NS {\n"
" class MyClass {\n"
" MyClass();\n"
" ~MyClass();\n"
" };\n"
"}\n"
"using namespace NS;\n"
"MyClass::~MyClass() { }\n"
"MyClass::MyClass() { }\n");
ASSERT(db && !db->functionScopes.empty() && db->functionScopes.front()->function && db->functionScopes.front()->function->functionScope == db->functionScopes.front());
const Token *f = Token::findsimplematch(tokenizer.tokens(), "MyClass ( ) ;");
ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 3 && f->function()->token->linenr() == 9);
f = Token::findsimplematch(tokenizer.tokens(), "~ MyClass ( ) ;");
f = f->next();
ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 4 && f->function()->token->linenr() == 8);
}
void isImplicitlyVirtual() {
{
GET_SYMBOL_DB("class Base {\n"