Support prefix-increment/decrement in CheckAutoVariables::assignFunctionArg() (#3177)
This commit is contained in:
parent
1227a3f596
commit
1715969f6f
|
@ -178,15 +178,19 @@ void CheckAutoVariables::assignFunctionArg()
|
||||||
for (std::size_t i = 0; i < functions; ++i) {
|
for (std::size_t i = 0; i < functions; ++i) {
|
||||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||||
for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
|
for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
|
||||||
if (Token::Match(tok, "[;{}] %var% =|++|--") &&
|
if (Token::Match(tok, "[;{}] %var% =|++|--") || Token::Match(tok, "[;{}] ++|-- %var%")) {
|
||||||
isNonReferenceArg(tok->next()) &&
|
const Token* vartok = tok->next();
|
||||||
!Token::Match(tok->tokAt(2), "= %varid% ;", tok->next()->varId()) &&
|
if (!vartok->variable())
|
||||||
!variableIsUsedInScope(Token::findsimplematch(tok->tokAt(2), ";"), tok->next()->varId(), scope) &&
|
vartok = vartok->next();
|
||||||
!Token::findsimplematch(tok, "goto", scope->classEnd)) {
|
if (isNonReferenceArg(vartok) &&
|
||||||
if (tok->next()->variable()->isPointer() && printWarning)
|
!Token::Match(vartok->next(), "= %varid% ;", vartok->varId()) &&
|
||||||
errorUselessAssignmentPtrArg(tok->next());
|
!variableIsUsedInScope(Token::findsimplematch(vartok->next(), ";"), vartok->varId(), scope) &&
|
||||||
else if (printStyle)
|
!Token::findsimplematch(vartok, "goto", scope->classEnd)) {
|
||||||
errorUselessAssignmentArg(tok->next());
|
if (vartok->variable()->isPointer() && printWarning)
|
||||||
|
errorUselessAssignmentPtrArg(vartok);
|
||||||
|
else if (printStyle)
|
||||||
|
errorUselessAssignmentArg(vartok);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -328,6 +328,11 @@ private:
|
||||||
" ptr++;\n"
|
" ptr++;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout.str());
|
||||||
|
|
||||||
|
check("void foo(int* ptr) {\n" // #3177
|
||||||
|
" --ptr;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testautovar11() { // #4641 - fp, assign local struct member address to function parameter
|
void testautovar11() { // #4641 - fp, assign local struct member address to function parameter
|
||||||
|
|
Loading…
Reference in New Issue