Skip to content

Commit 4127885

Browse files
authored
improve noConstructor message (#3750)
1 parent 8f7770f commit 4127885

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

lib/checkclass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,8 +967,8 @@ void CheckClass::noConstructorError(const Token *tok, const std::string &classna
967967
// For performance reasons the constructor might be intentionally missing. Therefore this is not a "warning"
968968
reportError(tok, Severity::style, "noConstructor",
969969
"$symbol:" + classname + "\n" +
970-
"The " + std::string(isStruct ? "struct" : "class") + " '$symbol' does not have a constructor although it has private member variables.\n"
971-
"The " + std::string(isStruct ? "struct" : "class") + " '$symbol' does not have a constructor "
970+
"The " + std::string(isStruct ? "struct" : "class") + " '$symbol' does not declare a constructor although it has private member variables which likely require initialization.\n"
971+
"The " + std::string(isStruct ? "struct" : "class") + " '$symbol' does not declare a constructor "
972972
"although it has private member variables. Member variables of builtin types are left "
973973
"uninitialized when the class is instantiated. That may cause bugs or undefined behavior.", CWE398, Certainty::normal);
974974
}

test/testconstructors.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,14 @@ class TestConstructors : public TestFixture {
242242
"private:\n"
243243
" int i;\n"
244244
"};");
245-
ASSERT_EQUALS("[test.cpp:1]: (style) The class 'Fred' does not have a constructor although it has private member variables.\n", errout.str());
245+
ASSERT_EQUALS("[test.cpp:1]: (style) The class 'Fred' does not declare a constructor although it has private member variables which likely require initialization.\n", errout.str());
246246

247247
check("struct Fred\n"
248248
"{\n"
249249
"private:\n"
250250
" int i;\n"
251251
"};");
252-
ASSERT_EQUALS("[test.cpp:1]: (style) The struct 'Fred' does not have a constructor although it has private member variables.\n", errout.str());
252+
ASSERT_EQUALS("[test.cpp:1]: (style) The struct 'Fred' does not declare a constructor although it has private member variables which likely require initialization.\n", errout.str());
253253
}
254254

255255

@@ -403,8 +403,8 @@ class TestConstructors : public TestFixture {
403403
check("struct Fred { int x; };\n"
404404
"class Barney { Fred fred; };\n"
405405
"class Wilma { struct Betty { int x; } betty; };");
406-
ASSERT_EQUALS("[test.cpp:2]: (style) The class 'Barney' does not have a constructor although it has private member variables.\n"
407-
"[test.cpp:3]: (style) The class 'Wilma' does not have a constructor although it has private member variables.\n", errout.str());
406+
ASSERT_EQUALS("[test.cpp:2]: (style) The class 'Barney' does not declare a constructor although it has private member variables which likely require initialization.\n"
407+
"[test.cpp:3]: (style) The class 'Wilma' does not declare a constructor although it has private member variables which likely require initialization.\n", errout.str());
408408
}
409409

410410
void simple9() { // ticket #4574
@@ -521,7 +521,7 @@ class TestConstructors : public TestFixture {
521521
"{\n"
522522
" int i;\n"
523523
"};");
524-
ASSERT_EQUALS("[test.cpp:1]: (style) The class 'Fred' does not have a constructor although it has private member variables.\n", errout.str());
524+
ASSERT_EQUALS("[test.cpp:1]: (style) The class 'Fred' does not declare a constructor although it has private member variables which likely require initialization.\n", errout.str());
525525
}
526526

527527
void noConstructor2() {

0 commit comments

Comments
 (0)