Skip to content

Commit 299835d

Browse files
committed
classPublicInterfaceDivZero: don't warn in overloaded operators. It is normal behaviour that these are not protected.
1 parent 05e1e5e commit 299835d

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/checkclass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,6 +2457,8 @@ void CheckClass::checkPublicInterfaceDivZero(bool test)
24572457
continue;
24582458
if (!func->hasBody())
24592459
continue;
2460+
if (func->name().compare(0,8,"operator")==0)
2461+
continue;
24602462
for (const Token *tok = func->functionScope->classStart; tok; tok = tok->next()) {
24612463
if (Token::Match(tok, "if|}"))
24622464
break;

test/testclass.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6527,6 +6527,13 @@ class TestClass : public TestFixture {
65276527
"void A::f1() {}\n"
65286528
"void A::f2(int x) { int a = 1000 / x; }");
65296529
ASSERT_EQUALS("[test.cpp:7]: (warning) Arbitrary usage of public method A::f2() could result in division by zero.\n", errout.str());
6530+
6531+
checkPublicInterfaceDivZero("class A {\n"
6532+
"public:\n"
6533+
" void operator/(int x);\n"
6534+
"}\n"
6535+
"void A::operator/(int x) { int a = 1000 / x; }");
6536+
ASSERT_EQUALS("", errout.str());
65306537
}
65316538
};
65326539

0 commit comments

Comments
 (0)