Fixed #521 (Tokenizer: improve static variable detection)

Also change cppcheck default behavior to don't show "If you see this,
there is a bug" message for each variable without varId. This feature
was very helpful for developers but may annoying users.

http://sourceforge.net/apps/trac/cppcheck/ticket/521
This commit is contained in:
Slava Semushin 2009-08-01 00:39:55 +07:00
parent fa8e1c82f0
commit 8588012df7
3 changed files with 8 additions and 1 deletions

View File

@ -304,6 +304,9 @@ void CheckStl::pushback()
if (Token::Match(tok2, "for ( %varid% = %var% . begin ( ) ; %varid% != %var% . end ( ) ; ++ %varid% ) {", iteratorid))
{
const unsigned int vectorid(tok2->tokAt(4)->varId());
if (vectorid == 0)
continue;
const Token *pushback = 0;
int indent3 = 0;
for (const Token *tok3 = tok2->tokAt(22); tok3; tok3 = tok3->next())

View File

@ -745,7 +745,7 @@ void Tokenizer::setVarId()
if (Token::Match(tok, "else|return|typedef|delete"))
continue;
if (tok->str() == "const")
if (Token::Match(tok, "const|static|extern"))
tok = tok->next();
while (Token::Match(tok, "%var% ::"))

View File

@ -1278,6 +1278,8 @@ private:
"std::map<int, int> coords;\n"
"std::tr1::unordered_map<int, int> xy;\n"
"std::list<boost::wave::token_id> tokens;\n"
"static std::vector<CvsProcess*> ex1;\n"
"extern std::vector<CvsProcess*> ex2;\n"
);
// tokenize..
@ -1295,6 +1297,8 @@ private:
"4: std :: map < int , int > coords@4 ;\n"
"5: std :: tr1 :: unordered_map < int , int > xy@5 ;\n"
"6: std :: list < boost :: wave :: token_id > tokens@6 ;\n"
"7: static std :: vector < CvsProcess * > ex1@7 ;\n"
"8: extern std :: vector < CvsProcess * > ex2@8 ;\n"
);
ASSERT_EQUALS(expected, actual);