Skip to content

Commit 4cb3548

Browse files
committed
unsafeClassDivZero: change severity to style
1 parent 5de3c43 commit 4cb3548

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lib/checkclass.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,7 +2443,10 @@ void CheckClass::copyCtorAndEqOperatorError(const Token *tok, const std::string
24432443

24442444
void CheckClass::checkUnsafeClassDivZero(bool test)
24452445
{
2446-
if (!_settings->isEnabled(Settings::WARNING))
2446+
// style severity: it is a style decision if classes should be safe or
2447+
// if users should be required to be careful. I expect that many users
2448+
// will disagree about these reports.
2449+
if (!_settings->isEnabled(Settings::STYLE))
24472450
return;
24482451

24492452
const std::size_t classes = symbolDatabase->classAndStructScopes.size();
@@ -2481,5 +2484,5 @@ void CheckClass::checkUnsafeClassDivZero(bool test)
24812484
void CheckClass::unsafeClassDivZeroError(const Token *tok, const std::string &className, const std::string &methodName, const std::string &varName)
24822485
{
24832486
const std::string s = className + "::" + methodName + "()";
2484-
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.");
2487+
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.");
24852488
}

test/testclass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6499,7 +6499,7 @@ class TestClass : public TestFixture {
64996499
// Clear the error log
65006500
errout.str("");
65016501
Settings settings;
6502-
settings.addEnabled("warning");
6502+
settings.addEnabled("style");
65036503

65046504
// Tokenize..
65056505
Tokenizer tokenizer(&settings, this);
@@ -6517,7 +6517,7 @@ class TestClass : public TestFixture {
65176517
" void dostuff(int x);\n"
65186518
"}\n"
65196519
"void A::dostuff(int x) { int a = 1000 / x; }");
6520-
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());
6520+
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());
65216521

65226522
checkUnsafeClassDivZero("class A {\n"
65236523
"public:\n"
@@ -6526,7 +6526,7 @@ class TestClass : public TestFixture {
65266526
"}\n"
65276527
"void A::f1() {}\n"
65286528
"void A::f2(int x) { int a = 1000 / x; }");
6529-
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());
6529+
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());
65306530

65316531
checkUnsafeClassDivZero("class A {\n"
65326532
"public:\n"

0 commit comments

Comments
 (0)