Fixed #7192 (False positive: uninitMemberVar when base class is in another namespace)

This commit is contained in:
Daniel Marjamäki 2016-01-09 12:18:36 +01:00
parent e038dd9663
commit 7191733981
2 changed files with 31 additions and 9 deletions

View File

@ -2954,20 +2954,28 @@ void Tokenizer::setVarId()
tok2 = tok2->linkAt(2);
// constructor with initializer list
if (Token::Match(tok2, ") : %name% (|{|<")) {
if (Token::Match(tok2, ") : %name%")) {
Token *tok3 = tok2;
do {
Token *vartok = tok3->tokAt(2);
std::map<std::string, unsigned int>::const_iterator varpos = thisClassVars.find(vartok->str());
while (Token::Match(tok3, "[)}] [,:]")) {
tok3 = tok3->tokAt(2);
while (Token::Match(tok3, "%name% :: %name%"))
tok3 = tok3->tokAt(2);
if (!Token::Match(tok3, "%name% (|{|<"))
break;
// set varid
std::map<std::string, unsigned int>::const_iterator varpos = thisClassVars.find(tok3->str());
if (varpos != thisClassVars.end())
vartok->varId(varpos->second);
if (vartok->strAt(1) == "<") {
tok3 = vartok->next()->findClosingBracket();
tok3->varId(varpos->second);
// goto end of var
if (tok3->strAt(1) == "<") {
tok3 = tok3->next()->findClosingBracket();
if (tok3 && tok3->next() && tok3->next()->link())
tok3 = tok3->next()->link();
} else
tok3 = vartok->linkAt(1);
} while (Token::Match(tok3, ")|} [:,] %name% (|{|<"));
tok3 = tok3->linkAt(1);
}
if (Token::Match(tok3, ")|} {")) {
setVarIdClassFunction(classname, tok2, tok3->next()->link(), thisClassVars, structMembers, &_varId);
}

View File

@ -123,6 +123,7 @@ private:
TEST_CASE(varid_in_class19);
TEST_CASE(varid_initList);
TEST_CASE(varid_initListWithBaseTemplate);
TEST_CASE(varid_initListWithScope);
TEST_CASE(varid_operator);
TEST_CASE(varid_throw);
TEST_CASE(varid_unknown_macro); // #2638 - unknown macro is not type
@ -1977,6 +1978,19 @@ private:
tokenize(code5));
}
void varid_initListWithScope() {
const char code1[] = "class A : public B::C {\n"
" A() : B::C(), x(0) {}\n"
" int x;\n"
"};";
ASSERT_EQUALS("\n\n##file 0\n"
"1: class A : public B :: C {\n"
"2: A ( ) : B :: C ( ) , x@1 ( 0 ) { }\n"
"3: int x@1 ;\n"
"4: } ;\n",
tokenize(code1));
}
void varid_operator() {
{
const std::string actual = tokenize(