Uninitialized Member variable: Fixed FP when delegate constructor is used
This commit is contained in:
parent
fd9ca16e51
commit
8509159d1a
|
@ -598,28 +598,31 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
|
||||||
initVar(ftok->varId(), scope, usage);
|
initVar(ftok->varId(), scope, usage);
|
||||||
} else { // c++11 delegate constructor
|
} else { // c++11 delegate constructor
|
||||||
const Function *member = ftok->function();
|
const Function *member = ftok->function();
|
||||||
// member function found
|
// member function not found => assume it initializes all members
|
||||||
if (member) {
|
if (!member) {
|
||||||
// recursive call
|
assignAllVar(usage);
|
||||||
// assume that all variables are initialized
|
return;
|
||||||
if (std::find(callstack.begin(), callstack.end(), member) != callstack.end()) {
|
}
|
||||||
/** @todo false negative: just bail */
|
|
||||||
assignAllVar(usage);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// member function has implementation
|
// recursive call
|
||||||
if (member->hasBody()) {
|
// assume that all variables are initialized
|
||||||
// initialize variable use list using member function
|
if (std::find(callstack.begin(), callstack.end(), member) != callstack.end()) {
|
||||||
callstack.push_back(member);
|
/** @todo false negative: just bail */
|
||||||
initializeVarList(*member, callstack, scope, usage);
|
assignAllVar(usage);
|
||||||
callstack.pop_back();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// there is a called member function, but it has no implementation, so we assume it initializes everything
|
// member function has implementation
|
||||||
else {
|
if (member->hasBody()) {
|
||||||
assignAllVar(usage);
|
// initialize variable use list using member function
|
||||||
}
|
callstack.push_back(member);
|
||||||
|
initializeVarList(*member, callstack, scope, usage);
|
||||||
|
callstack.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
// there is a called member function, but it has no implementation, so we assume it initializes everything
|
||||||
|
else {
|
||||||
|
assignAllVar(usage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (level != 0 && Token::Match(ftok, "%name% =")) // assignment in the initializer: var(value = x)
|
} else if (level != 0 && Token::Match(ftok, "%name% =")) // assignment in the initializer: var(value = x)
|
||||||
|
|
|
@ -96,6 +96,7 @@ private:
|
||||||
TEST_CASE(initvar_staticvar);
|
TEST_CASE(initvar_staticvar);
|
||||||
TEST_CASE(initvar_union);
|
TEST_CASE(initvar_union);
|
||||||
TEST_CASE(initvar_delegate); // ticket #4302
|
TEST_CASE(initvar_delegate); // ticket #4302
|
||||||
|
TEST_CASE(initvar_delegate2);
|
||||||
|
|
||||||
TEST_CASE(initvar_private_constructor); // BUG 2354171 - private constructor
|
TEST_CASE(initvar_private_constructor); // BUG 2354171 - private constructor
|
||||||
TEST_CASE(initvar_copy_constructor); // ticket #1611
|
TEST_CASE(initvar_copy_constructor); // ticket #1611
|
||||||
|
@ -1138,6 +1139,29 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void initvar_delegate2() {
|
||||||
|
check("class Foo {\n"
|
||||||
|
"public:\n"
|
||||||
|
" explicit Foo(const Bar bar);\n"
|
||||||
|
" Foo(const std::string& id);\n"
|
||||||
|
" virtual ~RtpSession() { }\n"
|
||||||
|
"protected:\n"
|
||||||
|
" bool a;\n"
|
||||||
|
" uint16_t b;\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"Foo::Foo(const Bar var)\n"
|
||||||
|
" : Foo(bar->getId())\n"
|
||||||
|
"{\n"
|
||||||
|
"}\n"
|
||||||
|
"\n"
|
||||||
|
"Foo::Foo(const std::string& id)\n"
|
||||||
|
" : a(true)\n"
|
||||||
|
" , b(0)\n"
|
||||||
|
"{\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void initvar_private_constructor() {
|
void initvar_private_constructor() {
|
||||||
settings.standards.cpp = Standards::CPP11;
|
settings.standards.cpp = Standards::CPP11;
|
||||||
|
|
Loading…
Reference in New Issue