diff --git a/lib/checkother.cpp b/lib/checkother.cpp index d3243e3e2..132467294 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -323,7 +323,10 @@ void CheckOther::checkUnsignedDivision() else if (Token::Match(tok, "[{};(,] unsigned %type% %var% [;=,)]")) varsign[tok->tokAt(3)->varId()] = 'u'; - else if (!Token::Match(tok, "[).]") && Token::Match(tok->next(), "%var% / %var%")) + else if (!Token::Match(tok, "[).]") && + Token::Match(tok->next(), "%var% / %var%") && + tok->tokAt(1)->varId() != 0 && + tok->tokAt(3)->varId() != 0) { if (ErrorLogger::udivWarning(*_settings)) { diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 407703096..3f9a0c796 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1830,9 +1830,12 @@ void Tokenizer::setVarId() if (Token::Match(tok, "[,;{}(] %type%")) tok = tok->next(); - if (tok->str() == "new" || tok->str() == "unsigned") + if (tok->str() == "new") continue; + if (tok->str() == "unsigned") + tok = tok->next(); + if (Token::Match(tok, "class|struct %type% :|{|;")) continue; diff --git a/test/testdivision.cpp b/test/testdivision.cpp index 6486a4e5b..4e8e0f1f9 100644 --- a/test/testdivision.cpp +++ b/test/testdivision.cpp @@ -115,6 +115,17 @@ private: " result = i2 / i1;}\n" ); ASSERT_EQUALS("", errout.str()); + + check("void f1()\n" + "{\n" + " unsigned int num = 0;\n" + "}\n" + "\n" + "void f2(int X)\n" + "{\n" + " X = X / z;}\n" + ); + ASSERT_EQUALS("", errout.str()); } void division5()