diff --git a/checkother.cpp b/checkother.cpp index b2a040a57..8575389bd 100644 --- a/checkother.cpp +++ b/checkother.cpp @@ -809,7 +809,7 @@ static bool isOp(const Token *tok) tok->str() == ">" || tok->str() == ">=" || tok->str() == "<<" || - Token::Match(tok, "[+-*/%&|,[])?:]"))); + Token::Match(tok, "[+-*/%&!~|,[])?:]"))); } void CheckOther::functionVariableUsage() diff --git a/testunusedvar.cpp b/testunusedvar.cpp index 0ff2d16e4..f769f2b90 100644 --- a/testunusedvar.cpp +++ b/testunusedvar.cpp @@ -65,6 +65,7 @@ private: TEST_CASE( localvar6 ); TEST_CASE( localvarMod ); // Usage with modulo + TEST_CASE( localvarInvert ); // Usage with inverted variable TEST_CASE( localvarIf ); // Usage in if TEST_CASE( localvarIfElse ); // return tmp1 ? tmp2 : tmp3; } @@ -212,6 +213,16 @@ private: ASSERT_EQUALS( std::string(""), errout.str() ); } + void localvarInvert() + { + functionVariableUsage( "int main()\n" + "{\n" + " int tmp = 10;\n" + " return ~tmp;\n" + "}\n" ); + ASSERT_EQUALS( std::string(""), errout.str() ); + } + void localvarIf() { functionVariableUsage( "int main()\n"