diff --git a/lib/checktype.cpp b/lib/checktype.cpp index 3b87f51c1..c9c9179f0 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -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; diff --git a/test/testtype.cpp b/test/testtype.cpp index 9378a14c7..31d27017c 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -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()); } };