From 299835da2ff3674dcdb0225c8ec9b64fd1783a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 21 Oct 2017 08:56:23 +0200 Subject: [PATCH] classPublicInterfaceDivZero: don't warn in overloaded operators. It is normal behaviour that these are not protected. --- lib/checkclass.cpp | 2 ++ test/testclass.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 34c44d213..e52e5d84f 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -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; diff --git a/test/testclass.cpp b/test/testclass.cpp index 82e70b33e..3495ee7e6 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -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()); } };