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:
parent
94ab34d797
commit
87b69a10fa
|
@ -164,7 +164,11 @@ void CheckClass::constructors()
|
||||||
void CheckClass::noConstructorError(const Token *tok, const std::string &classname, bool isStruct)
|
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"
|
// 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)
|
void CheckClass::uninitVarError(const Token *tok, const std::string &classname, const std::string &varname)
|
||||||
|
|
|
@ -2539,7 +2539,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
"};\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()
|
void noConstructor2()
|
||||||
|
|
|
@ -96,7 +96,7 @@ private:
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
"};\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"
|
check("struct Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -109,7 +109,7 @@ private:
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
"};\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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue