Ticket #2240 (Improve no constructor-message).

Improve the message about missing constructor but having class
attributes. Have proper short and long messages.
This commit is contained in:
Kimmo Varis 2010-11-27 10:17:03 +02:00
parent 94ab34d797
commit 87b69a10fa
3 changed files with 8 additions and 4 deletions

View File

@ -164,7 +164,11 @@ void CheckClass::constructors()
void CheckClass::noConstructorError(const Token *tok, const std::string &classname, bool isStruct)
{
// For performance reasons the constructor might be intentionally missing. Therefore this is not a "warning"
reportError(tok, Severity::style, "noConstructor", "The " + std::string(isStruct ? "struct" : "class") + " '" + classname + "' has no constructor. Member variables not initialized.");
reportError(tok, Severity::style, "noConstructor",
"The " + std::string(isStruct ? "struct" : "class") + " '" + classname +
"' does not have a constructor.\n"
"The class 'classname' does not have a constructor but it has attributes. "
"The attributes are not initialized which may cause bugs or undefined behavior.");
}
void CheckClass::uninitVarError(const Token *tok, const std::string &classname, const std::string &varname)

View File

@ -2539,7 +2539,7 @@ private:
"{\n"
" int i;\n"
"};\n");
ASSERT_EQUALS("[test.cpp:1]: (style) The class 'Fred' has no constructor. Member variables not initialized.\n", errout.str());
ASSERT_EQUALS("[test.cpp:1]: (style) The class 'Fred' does not have a constructor.\n", errout.str());
}
void noConstructor2()

View File

@ -96,7 +96,7 @@ private:
"private:\n"
" int i;\n"
"};\n");
ASSERT_EQUALS("[test.cpp:1]: (style) The class 'Fred' has no constructor. Member variables not initialized.\n", errout.str());
ASSERT_EQUALS("[test.cpp:1]: (style) The class 'Fred' does not have a constructor.\n", errout.str());
check("struct Fred\n"
"{\n"
@ -109,7 +109,7 @@ private:
"private:\n"
" int i;\n"
"};\n");
ASSERT_EQUALS("[test.cpp:1]: (style) The struct 'Fred' has no constructor. Member variables not initialized.\n", errout.str());
ASSERT_EQUALS("[test.cpp:1]: (style) The struct 'Fred' does not have a constructor.\n", errout.str());
}