From 8588012df780afb7efd9bbf5745d72edd107a05f Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 1 Aug 2009 00:39:55 +0700 Subject: [PATCH] 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 --- src/checkstl.cpp | 3 +++ src/tokenize.cpp | 2 +- test/testtokenize.cpp | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/checkstl.cpp b/src/checkstl.cpp index c2b48fef5..4f121b762 100644 --- a/src/checkstl.cpp +++ b/src/checkstl.cpp @@ -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()) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index fe686da86..604f3cb6b 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -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% ::")) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 7cbc6afbc..e2a58a21f 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -1278,6 +1278,8 @@ private: "std::map coords;\n" "std::tr1::unordered_map xy;\n" "std::list tokens;\n" + "static std::vector ex1;\n" + "extern std::vector 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);