Fixed ticket #574 (Tokenizer: not assign varId when variable first afer keyword and has long type)
http://sourceforge.net/apps/trac/cppcheck/ticket/574
This commit is contained in:
parent
1fd2c0ff28
commit
c66103f7bc
|
@ -745,7 +745,7 @@ void Tokenizer::setVarId()
|
|||
if (Token::Match(tok, "else|return|typedef|delete"))
|
||||
continue;
|
||||
|
||||
if (Token::Match(tok, "const|static|extern"))
|
||||
if (Token::Match(tok, "const|static|extern|public:|private:|protected:"))
|
||||
tok = tok->next();
|
||||
|
||||
while (Token::Match(tok, "%var% ::"))
|
||||
|
|
|
@ -97,6 +97,7 @@ private:
|
|||
TEST_CASE(varid_delete);
|
||||
TEST_CASE(varid_functions);
|
||||
TEST_CASE(varid_reference_to_containers);
|
||||
TEST_CASE(varid_in_class);
|
||||
|
||||
TEST_CASE(varidclass1);
|
||||
TEST_CASE(varidclass2);
|
||||
|
@ -1444,6 +1445,34 @@ private:
|
|||
ASSERT_EQUALS(expected, actual);
|
||||
}
|
||||
|
||||
void varid_in_class()
|
||||
{
|
||||
const std::string code("class Foo\n"
|
||||
"{\n"
|
||||
"public:\n"
|
||||
" std::string name1;\n"
|
||||
" std::string name2;\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: class Foo\n"
|
||||
"2: {\n"
|
||||
"3: public:\n"
|
||||
"4: std :: string name1@1 ;\n"
|
||||
"5: std :: string name2@2 ;\n"
|
||||
"6: } ;\n");
|
||||
|
||||
ASSERT_EQUALS(expected, actual);
|
||||
}
|
||||
|
||||
void varidclass1()
|
||||
{
|
||||
const std::string code("class Fred\n"
|
||||
|
|
Loading…
Reference in New Issue