From 0884204c2ff705336e915643e11ec865425f802e Mon Sep 17 00:00:00 2001 From: Daniel Marjamaki Date: Wed, 2 Nov 2011 18:31:13 +0100 Subject: [PATCH] Fixed #3279 (Token::Match called with varid 0) --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index f126bae84..a3db1ae3c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3480,7 +3480,7 @@ void Tokenizer::setVarId() std::string varname; Token *tok2 = tok ? tok->next() : 0; while (tok2) { - if (tok2->isName()) + if (tok2->isName() && tok2->str() != "const") varname = tok2->str(); else if (tok2->str() != "*" && tok2->str() != "&") break; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 6e9440ff2..a6aadd3b4 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -186,6 +186,7 @@ private: TEST_CASE(varid36); // ticket #2980 (segmentation fault) TEST_CASE(varid37); // ticket #3092 (varid for 'Bar bar(*this);') TEST_CASE(varid38); // ticket #3272 (varid for 'FOO class C;') + TEST_CASE(varid39); // ticket #3279 (varid for 'FOO::BAR const') TEST_CASE(varidFunctionCall1); TEST_CASE(varidFunctionCall2); TEST_CASE(varidFunctionCall3); @@ -2955,6 +2956,13 @@ private: tokenizeDebugListing(code)); } + void varid39() { + const std::string code = "void f(FOO::BAR const);\n"; + ASSERT_EQUALS("\n\n##file 0\n" + "1: void f ( FOO :: BAR const ) ;\n", + tokenizeDebugListing(code)); + } + void varidFunctionCall1() { const std::string code("void f() {\n" " int x;\n"