From 53c120c701bc4f11652b6961ec4dafa720a65f54 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 18 Jul 2009 17:37:51 +0700 Subject: [PATCH] Fixed ticket #479 (varId not assigned to reference to standart container) http://sourceforge.net/apps/trac/cppcheck/ticket/479 --- src/tokenize.cpp | 2 +- test/testtokenize.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 17174e2e9..4d75637f0 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -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 diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 33a01bc6b..2b96fb9cb 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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 b;\n" + " std::vector &a = b;\n" + " std::vector *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"