Fixed #4536 (non-static member initializer causes false positive)
This commit is contained in:
parent
73e2a8fdb5
commit
e6915e7a78
|
@ -109,6 +109,10 @@ void CheckClass::constructors()
|
||||||
std::list<Variable>::const_iterator var;
|
std::list<Variable>::const_iterator var;
|
||||||
unsigned int count = 0;
|
unsigned int count = 0;
|
||||||
for (var = scope->varlist.begin(); var != scope->varlist.end(); ++var, ++count) {
|
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;
|
bool inconclusive = false;
|
||||||
|
|
||||||
if (usage[count].assign || usage[count].init || var->isStatic())
|
if (usage[count].assign || usage[count].init || var->isStatic())
|
||||||
|
|
|
@ -1075,6 +1075,12 @@ void Variable::evaluate()
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
setFlag(fHasDefault, tok->str() == "=");
|
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)
|
bool Function::argsMatch(const Scope *scope, const Token *first, const Token *second, const std::string &path, unsigned int depth)
|
||||||
|
|
|
@ -63,6 +63,7 @@ private:
|
||||||
TEST_CASE(simple8);
|
TEST_CASE(simple8);
|
||||||
TEST_CASE(simple9); // ticket #4574
|
TEST_CASE(simple9); // ticket #4574
|
||||||
TEST_CASE(simple10); // ticket #4388
|
TEST_CASE(simple10); // ticket #4388
|
||||||
|
TEST_CASE(simple11); // ticket #4536
|
||||||
|
|
||||||
TEST_CASE(initvar_with_this); // BUG 2190300
|
TEST_CASE(initvar_with_this); // BUG 2190300
|
||||||
TEST_CASE(initvar_if); // BUG 2190290
|
TEST_CASE(initvar_if); // BUG 2190290
|
||||||
|
@ -342,6 +343,16 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
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() {
|
void initvar_with_this() {
|
||||||
check("struct Fred\n"
|
check("struct Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue