From 4cb3548e2bad3ebfaee009e730b04de22b608766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 21 Oct 2017 21:51:58 +0200 Subject: [PATCH] unsafeClassDivZero: change severity to style --- lib/checkclass.cpp | 7 +++++-- test/testclass.cpp | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 1c614c5a7..25d9d1d9b 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2443,7 +2443,10 @@ void CheckClass::copyCtorAndEqOperatorError(const Token *tok, const std::string void CheckClass::checkUnsafeClassDivZero(bool test) { - if (!_settings->isEnabled(Settings::WARNING)) + // style severity: it is a style decision if classes should be safe or + // if users should be required to be careful. I expect that many users + // will disagree about these reports. + if (!_settings->isEnabled(Settings::STYLE)) return; const std::size_t classes = symbolDatabase->classAndStructScopes.size(); @@ -2481,5 +2484,5 @@ void CheckClass::checkUnsafeClassDivZero(bool test) void CheckClass::unsafeClassDivZeroError(const Token *tok, const std::string &className, const std::string &methodName, const std::string &varName) { const std::string s = className + "::" + methodName + "()"; - reportError(tok, Severity::warning, "unsafeClassDivZero", "Public interface of " + className + " is not safe. When calling " + s + ", if parameter " + varName + " is 0 that leads to division by zero."); + reportError(tok, Severity::style, "unsafeClassDivZero", "Public interface of " + className + " is not safe. When calling " + s + ", if parameter " + varName + " is 0 that leads to division by zero."); } diff --git a/test/testclass.cpp b/test/testclass.cpp index a8b13c5b3..fc41eabca 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -6499,7 +6499,7 @@ private: // Clear the error log errout.str(""); Settings settings; - settings.addEnabled("warning"); + settings.addEnabled("style"); // Tokenize.. Tokenizer tokenizer(&settings, this); @@ -6517,7 +6517,7 @@ private: " void dostuff(int x);\n" "}\n" "void A::dostuff(int x) { int a = 1000 / x; }"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Public interface of A is not safe. When calling A::dostuff(), if parameter x is 0 that leads to division by zero.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (style) Public interface of A is not safe. When calling A::dostuff(), if parameter x is 0 that leads to division by zero.\n", errout.str()); checkUnsafeClassDivZero("class A {\n" "public:\n" @@ -6526,7 +6526,7 @@ private: "}\n" "void A::f1() {}\n" "void A::f2(int x) { int a = 1000 / x; }"); - ASSERT_EQUALS("[test.cpp:7]: (warning) Public interface of A is not safe. When calling A::f2(), if parameter x is 0 that leads to division by zero.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (style) Public interface of A is not safe. When calling A::f2(), if parameter x is 0 that leads to division by zero.\n", errout.str()); checkUnsafeClassDivZero("class A {\n" "public:\n"