diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index db5a62fd7..286e61ad6 100755 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2598,6 +2598,7 @@ void Tokenizer::setVarIdPass1() scopeStack.push(VarIdScopeInfo()); std::stack functionDeclEndStack; bool initlist = false; + bool inlineFunction = false; for (Token *tok = list.front(); tok; tok = tok->next()) { if (!functionDeclEndStack.empty() && tok == functionDeclEndStack.top()) { functionDeclEndStack.pop(); @@ -2625,6 +2626,8 @@ void Tokenizer::setVarIdPass1() scopeInfo.push(variableId); } } else if (Token::Match(tok, "{|}")) { + inlineFunction = false; + const Token * const startToken = (tok->str() == "{") ? tok : tok->link(); // parse anonymous unions as part of the current scope @@ -2682,7 +2685,7 @@ void Tokenizer::setVarIdPass1() Token::Match(tok, "[;{}]") || (tok->str() == "(" && isFunctionHead(tok,"{")) || (tok->str() == "(" && !scopeStack.top().isExecutable && isFunctionHead(tok,";:")) || - (tok->str() == "," && !scopeStack.top().isExecutable) || + (tok->str() == "," && (!scopeStack.top().isExecutable || inlineFunction)) || (tok->isName() && endsWith(tok->str(), ':')))) { // No variable declarations in sizeof @@ -2717,6 +2720,9 @@ void Tokenizer::setVarIdPass1() syntaxError(errTok); } if (decl) { + if (tok->str() == "(" && isFunctionHead(tok,"{") && scopeStack.top().isExecutable) + inlineFunction = true; + const Token* prev2 = tok2->previous(); if (Token::Match(prev2, "%type% [;[=,)]") && tok2->previous()->str() != "const") ; diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 445503c69..a4822735f 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -91,6 +91,7 @@ private: TEST_CASE(varid58); // #6638: for loop in for condition TEST_CASE(varid59); // #6696 TEST_CASE(varid60); // #7267 cast '(unsigned x)10' + TEST_CASE(varid61); // #4988 inline function TEST_CASE(varid_cpp_keywords_in_c_code); TEST_CASE(varid_cpp_keywords_in_c_code2); // #5373: varid=0 for argument called "delete" TEST_CASE(varidFunctionCall1); @@ -1050,6 +1051,16 @@ private: tokenize("a=(x y)10;", false)); } + void varid61() { + const char code[] = "void foo(int b) {\n" + " void bar(int a, int b) {}\n" + "}"; + const char expected[] = "1: void foo ( int b@1 ) {\n" + "2: void bar ( int a@2 , int b@3 ) { }\n" + "3: }\n"; + ASSERT_EQUALS(expected, tokenize(code, false)); + } + void varid_cpp_keywords_in_c_code() { const char code[] = "void f() {\n" " delete d;\n"