Fixed #5533 (False positive: 'Assignment of function parameter has no effect outside the function.')

This commit is contained in:
Daniel Marjamäki 2014-05-09 18:43:29 +02:00
parent dfe876fa4c
commit 1541e27e4a
2 changed files with 15 additions and 2 deletions

View File

@ -2485,9 +2485,9 @@ void Tokenizer::setVarId()
initlist = Token::simpleMatch(tok->link(), ") :");
// function declarations
} else if (!executableScope.top() && tok->str() == "(" && Token::simpleMatch(tok->link(), ") ;")) {
} else if (!executableScope.top() && tok->str() == "(" && Token::Match(tok->link(), ") const| ;")) {
scopeInfo.push(variableId);
} else if (!executableScope.top() && Token::simpleMatch(tok, ") ;")) {
} else if (!executableScope.top() && Token::Match(tok, ") const| ;")) {
variableId.swap(scopeInfo.top());
scopeInfo.pop();

View File

@ -292,6 +292,7 @@ private:
TEST_CASE(varid_in_class12); // #4637 - method
TEST_CASE(varid_in_class13); // #4637 - method
TEST_CASE(varid_in_class14);
TEST_CASE(varid_in_class15); // #5533 - functions
TEST_CASE(varid_initList);
TEST_CASE(varid_operator);
TEST_CASE(varid_throw);
@ -4566,6 +4567,18 @@ private:
"7: }\n", tokenizeDebugListing(code, false, "test.cpp"));
}
void varid_in_class15() { // #5533 - functions
const char code[] = "class Fred {\n"
" void x(int a) const;\n"
" void y() { a=0; }\n" // <- unknown variable
"}\n";
ASSERT_EQUALS("\n\n##file 0\n"
"1: class Fred {\n"
"2: void x ( int a@1 ) const ;\n"
"3: void y ( ) { a = 0 ; }\n"
"4: }\n", tokenizeDebugListing(code, false, "test.cpp"));
}
void varid_initList() {
const char code1[] = "class A {\n"
" A() : x(0) {}\n"