Fixed #4729 (Tokenizer::setVarId: Varid not tracked properly after function declaration with 'shadow' parameter name)

This commit is contained in:
Daniel Marjamäki 2013-04-19 18:36:16 +02:00
parent 8d9ad2ae0d
commit 9f8ce6f77f
2 changed files with 28 additions and 5 deletions

View File

@ -2753,6 +2753,14 @@ void Tokenizer::setVarId()
(Token::simpleMatch(tok->link(), ") {") || Token::Match(tok->link(), ") %type% {") || isInitList(tok->link()))) {
scopeInfo.push(variableId);
initlist = Token::simpleMatch(tok->link(), ") :");
// function declarations
} else if (!executableScope.top() && tok->str() == "(" && Token::simpleMatch(tok->link(), ") ;")) {
scopeInfo.push(variableId);
} else if (!executableScope.top() && Token::simpleMatch(tok, ") ;")) {
variableId.swap(scopeInfo.top());
scopeInfo.pop();
} else if (tok->str() == "{") {
initlist = false;
// parse anonymous unions as part of the current scope

View File

@ -3614,11 +3614,26 @@ private:
tokenizeDebugListing(code, false, "test.c"));
}
void varid47() { // #3768
const std::string code("void f(std::string &string, std::string &len) {}");
ASSERT_EQUALS("\n\n##file 0\n"
"1: void f ( std :: string & string@1 , std :: string & len@2 ) { }\n",
tokenizeDebugListing(code, false, "test.cpp"));
void varid47() { // function parameters
// #3768
{
const std::string code("void f(std::string &string, std::string &len) {}");
ASSERT_EQUALS("\n\n##file 0\n"
"1: void f ( std :: string & string@1 , std :: string & len@2 ) { }\n",
tokenizeDebugListing(code, false, "test.cpp"));
}
// #4729
{
const char code[] = "int x;\n"
"void a(int x);\n"
"void b() { x = 0; }\n";
ASSERT_EQUALS("\n\n##file 0\n"
"1: int x@1 ;\n"
"2: void a ( int x@2 ) ;\n"
"3: void b ( ) { x@1 = 0 ; }\n",
tokenizeDebugListing(code));
}
}
void varid48() { // #3785 - return (a*b)