Fixed ticket #479 (varId not assigned to reference to standart container)
http://sourceforge.net/apps/trac/cppcheck/ticket/479
This commit is contained in:
parent
69cbacfc87
commit
53c120c701
|
@ -760,7 +760,7 @@ void Tokenizer::setVarId()
|
|||
|
||||
if (Token::Match(tok2, "> %var%"))
|
||||
tok = tok2;
|
||||
else if (Token::Match(tok2, "> :: %var%"))
|
||||
else if (Token::Match(tok2, "> ::|*|& %var%"))
|
||||
tok = tok2->next();
|
||||
else
|
||||
continue; // Not code that I understand / not a variable declaration
|
||||
|
|
|
@ -116,6 +116,7 @@ private:
|
|||
TEST_CASE(varidStl);
|
||||
TEST_CASE(varid_delete);
|
||||
TEST_CASE(varid_functions);
|
||||
TEST_CASE(varid_reference_to_containers);
|
||||
|
||||
TEST_CASE(varidclass1);
|
||||
TEST_CASE(varidclass2);
|
||||
|
@ -1342,6 +1343,34 @@ private:
|
|||
|
||||
}
|
||||
|
||||
void varid_reference_to_containers()
|
||||
{
|
||||
const std::string code("void f()\n"
|
||||
"{\n"
|
||||
" std::vector<int> b;\n"
|
||||
" std::vector<int> &a = b;\n"
|
||||
" std::vector<int> *c = &b;\n"
|
||||
"}\n");
|
||||
|
||||
// tokenize..
|
||||
Tokenizer tokenizer;
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
tokenizer.setVarId();
|
||||
|
||||
// result..
|
||||
const std::string actual(tokenizer.tokens()->stringifyList(true));
|
||||
const std::string expected("\n\n##file 0\n"
|
||||
"1: void f ( )\n"
|
||||
"2: {\n"
|
||||
"3: std :: vector < int > b@1 ;\n"
|
||||
"4: std :: vector < int > & a@2 = b@1 ;\n"
|
||||
"5: std :: vector < int > * c@3 = & b@1 ;\n"
|
||||
"6: }\n");
|
||||
|
||||
ASSERT_EQUALS(expected, actual);
|
||||
}
|
||||
|
||||
void varidclass1()
|
||||
{
|
||||
const std::string code("class Fred\n"
|
||||
|
|
Loading…
Reference in New Issue