classPublicInterfaceDivZero: don't warn in overloaded operators. It is normal behaviour that these are not protected.

This commit is contained in:
Daniel Marjamäki 2017-10-21 08:56:23 +02:00
parent 05e1e5e0a0
commit 299835da2f
2 changed files with 9 additions and 0 deletions

View File

@ -2457,6 +2457,8 @@ void CheckClass::checkPublicInterfaceDivZero(bool test)
continue;
if (!func->hasBody())
continue;
if (func->name().compare(0,8,"operator")==0)
continue;
for (const Token *tok = func->functionScope->classStart; tok; tok = tok->next()) {
if (Token::Match(tok, "if|}"))
break;

View File

@ -6527,6 +6527,13 @@ private:
"void A::f1() {}\n"
"void A::f2(int x) { int a = 1000 / x; }");
ASSERT_EQUALS("[test.cpp:7]: (warning) Arbitrary usage of public method A::f2() could result in division by zero.\n", errout.str());
checkPublicInterfaceDivZero("class A {\n"
"public:\n"
" void operator/(int x);\n"
"}\n"
"void A::operator/(int x) { int a = 1000 / x; }");
ASSERT_EQUALS("", errout.str());
}
};