From 62f9875f90b945095c829346d4e9aec2918e5dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 13 May 2012 07:55:35 +0200 Subject: [PATCH] Fixed #3799 (Bug: Function gets varId) --- lib/tokenize.cpp | 2 +- test/testsymboldatabase.cpp | 4 ++-- test/testtokenize.cpp | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index f1c4a8bbc..dd500c1be 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2699,7 +2699,7 @@ void Tokenizer::setVarId() tok = tok2->previous(); } - else if (decl && Token::Match(tok2->previous(), "%type% ( !!)")) { + else if (decl && Token::Match(tok2->previous(), "%type% ( !!)") && Token::simpleMatch(tok2->link(), ") ;")) { // In C++ , a variable can't be called operator+ or something like that. if (isCPP() && tok2->previous()->str().size() >= 9 && diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 75d1a2b8c..681554318 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -724,8 +724,8 @@ private: void functionArgs1() { { GET_SYMBOL_DB("void f(std::vector, const std::vector & v) { }"); - TODO_ASSERT_EQUALS(1+1, 1+2, db->getVariableListSize()); - const Variable* v = db->getVariableFromVarId(2); // TODO: varId 1 + ASSERT_EQUALS(1+1, db->getVariableListSize()); + const Variable* v = db->getVariableFromVarId(1); ASSERT(v && v->isReference() && v->isConst() && v->isArgument()); const Scope* f = db->findScopeByName("f"); ASSERT(f && f->type == Scope::eFunction && f->function); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 30887fb69..a643dcaf7 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -214,6 +214,7 @@ private: TEST_CASE(varid46); // struct varname TEST_CASE(varid47); // function parameters TEST_CASE(varid48); // #3785 - return (a*b) + TEST_CASE(varid49); // #3799 - void f(std::vector) TEST_CASE(varid_cpp_keywords_in_c_code); TEST_CASE(varidFunctionCall1); TEST_CASE(varidFunctionCall2); @@ -3249,6 +3250,13 @@ private: tokenizeDebugListing(code, false, "test.c")); } + void varid49() { // #3799 - void f(std::vector) + const std::string code("void f(std::vector)"); + ASSERT_EQUALS("\n\n##file 0\n" + "1: void f ( std :: vector < int > )\n", + tokenizeDebugListing(code, false, "test.cpp")); + } + void varid_cpp_keywords_in_c_code() { const char code[] = "void f() {\n" " delete d;\n"