Fixed #4536 (non-static member initializer causes false positive)

This commit is contained in:
Robert Reif 2013-02-18 06:33:53 +01:00 committed by Daniel Marjamäki
parent 73e2a8fdb5
commit e6915e7a78
3 changed files with 21 additions and 0 deletions

View File

@ -109,6 +109,10 @@ void CheckClass::constructors()
std::list<Variable>::const_iterator var;
unsigned int count = 0;
for (var = scope->varlist.begin(); var != scope->varlist.end(); ++var, ++count) {
// check for C++11 initializer
if (var->hasDefault())
usage[count].init = true;
bool inconclusive = false;
if (usage[count].assign || usage[count].init || var->isStatic())

View File

@ -1075,6 +1075,12 @@ void Variable::evaluate()
tok = tok->link();
setFlag(fHasDefault, tok->str() == "=");
}
// check for C++11 member initialization
if (_scope && _scope->isClassOrStruct()) {
// type var = x; gets simplified to: type var ; var = x ;
if (Token::Match(_name, "%var% ; %var% = %any% ;") && _name->strAt(2) == _name->str())
setFlag(fHasDefault, true);
}
}
bool Function::argsMatch(const Scope *scope, const Token *first, const Token *second, const std::string &path, unsigned int depth)

View File

@ -63,6 +63,7 @@ private:
TEST_CASE(simple8);
TEST_CASE(simple9); // ticket #4574
TEST_CASE(simple10); // ticket #4388
TEST_CASE(simple11); // ticket #4536
TEST_CASE(initvar_with_this); // BUG 2190300
TEST_CASE(initvar_if); // BUG 2190290
@ -342,6 +343,16 @@ private:
ASSERT_EQUALS("", errout.str());
}
void simple11() { // ticket #4536
check("class Fred {\n"
"public:\n"
" Fred() {}\n"
"private:\n"
" int x = 0;\n"
"};");
ASSERT_EQUALS("", errout.str());
}
void initvar_with_this() {
check("struct Fred\n"
"{\n"