diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index fc904c33b..d98c653a1 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2587,9 +2587,16 @@ void Tokenizer::setVarId() continue; const Token *tok3 = tok2->next(); - if (!tok3->isStandardType() && tok3->str() != "void" && !Token::Match(tok3, "struct|union|class %type%") && tok3->str() != "." && (notstart.find(tok3->str()) != notstart.end() || !setVarIdParseDeclaration(&tok3, variableId, executableScope.top(), isCPP()))) { - variableId[tok2->previous()->str()] = ++_varId; - tok = tok2->previous(); + if (!tok3->isStandardType() && tok3->str() != "void" && !Token::Match(tok3, "struct|union|class %type%") && tok3->str() != "." && !Token::Match(tok2->link()->previous(), "[&*]")) { + bool isDecl = true; + for (; tok3 && isDecl; tok3 = tok3->nextArgument()) { + if (tok3->strAt(-1) == "&" || tok3->strAt(-1) == "*" || (notstart.find(tok3->str()) == notstart.end() && setVarIdParseDeclaration(&tok3, variableId, executableScope.top(), isCPP()))) + isDecl = false; + } + if (isDecl) { + variableId[tok2->previous()->str()] = ++_varId; + tok = tok2->previous(); + } } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index de481bef1..1a8e82ba8 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -299,6 +299,7 @@ private: TEST_CASE(varid_in_class14); TEST_CASE(varid_in_class15); // #5533 - functions TEST_CASE(varid_in_class16); + TEST_CASE(varid_in_class17); // #6056 - no varid for member functions TEST_CASE(varid_initList); TEST_CASE(varid_operator); TEST_CASE(varid_throw); @@ -4623,12 +4624,30 @@ private: const char code[] = "class Fred {\n" " int x;\n" " void foo(int x) { this->x = x; }\n" - "}\n"; + "};\n"; ASSERT_EQUALS("\n\n##file 0\n" "1: class Fred {\n" "2: int x@1 ;\n" "3: void foo ( int x@2 ) { this . x@1 = x@2 ; }\n" - "4: }\n", tokenizeDebugListing(code, false, "test.cpp")); + "4: } ;\n", tokenizeDebugListing(code, false, "test.cpp")); + } + + void varid_in_class17() { // #6056 - Set no varid for member functions + const char code[] = "class Fred {\n" + " int method_with_internal(X&);\n" + " int method_with_internal(X*);\n" + " int method_with_internal(int&);\n" + " int method_with_internal(A* b, X&);\n" + " int method_with_internal(X&, A* b);\n" + "};"; + ASSERT_EQUALS("\n\n##file 0\n" + "1: class Fred {\n" + "2: int method_with_internal ( X & ) ;\n" + "3: int method_with_internal ( X * ) ;\n" + "4: int method_with_internal ( int & ) ;\n" + "5: int method_with_internal ( A * b@1 , X & ) ;\n" + "6: int method_with_internal ( X & , A * b@2 ) ;\n" + "7: } ;\n", tokenizeDebugListing(code, false, "test.cpp")); } void varid_initList() {