Fixed #6214 (non-static member initializer causes false positive (function call; initializer))

This commit is contained in:
Frank Zingsheim 2014-10-12 15:06:07 +02:00 committed by Daniel Marjamäki
parent aac9e66147
commit 11867e3210
2 changed files with 8 additions and 3 deletions

View File

@ -1201,8 +1201,11 @@ void Variable::evaluate()
}
// check for C++11 member initialization
if (_scope && _scope->isClassOrStruct()) {
// type var = x or
// type var = {x}
// type var = x; gets simplified to: type var ; var = x ;
if (Token::Match(_name, "%var% ; %var% = %any% ;") && _name->strAt(2) == _name->str())
if ((Token::Match(_name, "%var% ; %var% = ") && _name->strAt(2) == _name->str()) ||
Token::Match(_name, "%var% {"))
setFlag(fHasDefault, true);
}

View File

@ -64,7 +64,7 @@ private:
TEST_CASE(simple8);
TEST_CASE(simple9); // ticket #4574
TEST_CASE(simple10); // ticket #4388
TEST_CASE(simple11); // ticket #4536
TEST_CASE(simple11); // ticket #4536, #6214
TEST_CASE(simple12); // ticket #4620
TEST_CASE(simple13); // #5498 - no constructor, c++11 assignments
@ -377,12 +377,14 @@ private:
ASSERT_EQUALS("", errout.str());
}
void simple11() { // ticket #4536
void simple11() { // ticket #4536, #6214
check("class Fred {\n"
"public:\n"
" Fred() {}\n"
"private:\n"
" int x = 0;\n"
" int y = f();\n"
" int z{0};\n"
"};");
ASSERT_EQUALS("", errout.str());
}