checkSignConversion: dont warn for + and -

This commit is contained in:
Daniel Marjamäki 2014-09-12 18:58:31 +02:00
parent 0e55f12140
commit 8cbd013d7f
2 changed files with 8 additions and 1 deletions

View File

@ -225,7 +225,7 @@ void CheckType::checkSignConversion()
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
if (!tok->isArithmeticalOp())
if (!tok->isArithmeticalOp() || Token::Match(tok,"+|-"))
continue;
unsigned int size = 0;

View File

@ -116,6 +116,13 @@ private:
"}\n"
"void f2() { f1(-4); }");
ASSERT_EQUALS("[test.cpp:1]: (warning) Suspicious code: sign conversion of x in calculation, even though x can have a negative value\n", errout.str());
// Dont warn for + and -
check("void f1(int x) {"
" a = x + 5U;\n"
"}\n"
"void f2() { f1(-4); }");
ASSERT_EQUALS("", errout.str());
}
};