unsafeClassDivZero: change severity to style

This commit is contained in:
Daniel Marjamäki 2017-10-21 21:51:58 +02:00
parent 5de3c43209
commit 4cb3548e2b
2 changed files with 8 additions and 5 deletions

View File

@ -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.");
}

View File

@ -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"