Fixed #4776 (FP: Assignment of function parameter has no effect outside the function, with goto)

This commit is contained in:
Daniel Marjamäki 2014-10-21 16:21:33 +02:00
parent e965d8de67
commit a3efa1e180
2 changed files with 14 additions and 1 deletions

View File

@ -130,7 +130,8 @@ void CheckAutoVariables::assignFunctionArg()
for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
if (Token::Match(tok, "[;{}] %var% =|++|--") &&
isNonReferenceArg(tok->next()) &&
!variableIsUsedInScope(Token::findsimplematch(tok->tokAt(2), ";"), tok->next()->varId(), scope)) {
!variableIsUsedInScope(Token::findsimplematch(tok->tokAt(2), ";"), tok->next()->varId(), scope) &&
!Token::findsimplematch(tok, "goto", scope->classEnd)) {
if (tok->next()->variable()->isPointer() && warning)
errorUselessAssignmentPtrArg(tok->next());
else if (style)

View File

@ -79,6 +79,7 @@ private:
TEST_CASE(testautovar11); // ticket #4641 - fp, assign local struct member address to function parameter
TEST_CASE(testautovar12); // ticket #5024 - crash
TEST_CASE(testautovar13); // ticket #5537 - crash
TEST_CASE(testautovar14); // ticket #4776 - assignment of function parameter, goto
TEST_CASE(testautovar_array1);
TEST_CASE(testautovar_array2);
TEST_CASE(testautovar_return1);
@ -378,6 +379,17 @@ private:
"};\n");
}
void testautovar14() { // Ticket #4776
check("void f(int x) {\n"
"label:"
" if (x>0) {\n"
" x = x >> 1;\n"
" goto label;\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void testautovar_array1() {
check("void func1(int* arr[2])\n"
"{\n"