noExplicitConstructor - Verbose error message edit (#5260)

The goal is to use keywords like "converting constructor" and "implicit
conversion" that will help users further study what this warning is
about. I think that the old message provided no context to the
uninitiated.
This commit is contained in:
Samuel Poláček 2023-08-01 11:21:23 +02:00 committed by GitHub
parent bfaa7c075a
commit e7a2585e0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -1067,7 +1067,7 @@ void CheckClass::noConstructorError(const Token *tok, const std::string &classna
void CheckClass::noExplicitConstructorError(const Token *tok, const std::string &classname, bool isStruct) void CheckClass::noExplicitConstructorError(const Token *tok, const std::string &classname, bool isStruct)
{ {
const std::string message(std::string(isStruct ? "Struct" : "Class") + " '$symbol' has a constructor with 1 argument that is not explicit."); const std::string message(std::string(isStruct ? "Struct" : "Class") + " '$symbol' has a constructor with 1 argument that is not explicit.");
const std::string verbose(message + " Such constructors should in general be explicit for type safety reasons. Using the explicit keyword in the constructor means some mistakes when using the class can be avoided."); const std::string verbose(message + " Such, so called \"Converting constructors\", should in general be explicit for type safety reasons as that prevents unintended implicit conversions.");
reportError(tok, Severity::style, "noExplicitConstructor", "$symbol:" + classname + '\n' + message + '\n' + verbose, CWE398, Certainty::normal); reportError(tok, Severity::style, "noExplicitConstructor", "$symbol:" + classname + '\n' + message + '\n' + verbose, CWE398, Certainty::normal);
} }