diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index cdf99a945..f1c4a8bbc 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2637,11 +2637,12 @@ void Tokenizer::setVarId() for (Token *tok = list.front(); tok; tok = tok->next()) { // scope info to handle shadow variables.. - if (tok->str() == "(" && Token::simpleMatch(tok->link(), ") {")) { + if (tok->str() == "(" && + (Token::simpleMatch(tok->link(), ") {") || Token::Match(tok->link(), ") %type% {"))) { scopeInfo.push(variableId); } else if (tok->str() == "{") { scopestartvarid.push(_varId); - if (Token::simpleMatch(tok->previous(), ")")) { + if (Token::simpleMatch(tok->previous(), ")") || Token::Match(tok->tokAt(-2), ") %type%")) { executableScope.push(true); } else { executableScope.push(executableScope.top()); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index addf93642..30887fb69 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -213,6 +213,7 @@ private: TEST_CASE(varid45); // #3466 TEST_CASE(varid46); // struct varname TEST_CASE(varid47); // function parameters + TEST_CASE(varid48); // #3785 - return (a*b) TEST_CASE(varid_cpp_keywords_in_c_code); TEST_CASE(varidFunctionCall1); TEST_CASE(varidFunctionCall2); @@ -3241,6 +3242,13 @@ private: tokenizeDebugListing(code, false, "test.cpp")); } + void varid48() { // #3785 - return (a*b) + const std::string code("int X::f(int b) const { return(a*b); }"); + ASSERT_EQUALS("\n\n##file 0\n" + "1: int X :: f ( int b@1 ) const { return ( a * b@1 ) ; }\n", + tokenizeDebugListing(code, false, "test.c")); + } + void varid_cpp_keywords_in_c_code() { const char code[] = "void f() {\n" " delete d;\n"