| 1170 | } |
| 1171 | |
| 1172 | void CheckClassImpl::uninitVarError(const Token *tok, bool isprivate, FunctionType functionType, const std::string &classname, const std::string &varname, bool derived, bool inconclusive, bool noCtor) |
| 1173 | { |
| 1174 | std::string message("Member variable '$symbol' "); |
| 1175 | if (noCtor) |
| 1176 | message += "has no initializer."; |
| 1177 | else { |
| 1178 | message += "is not initialized in the "; |
| 1179 | if (functionType == FunctionType::eCopyConstructor) |
| 1180 | message += "copy "; |
| 1181 | else if (functionType == FunctionType::eMoveConstructor) |
| 1182 | message += "move "; |
| 1183 | message += "constructor."; |
| 1184 | } |
| 1185 | if (derived) |
| 1186 | message += " Maybe it should be initialized directly in the class " + classname + "?"; |
| 1187 | std::string id = std::string("uninit") + (derived ? "Derived" : "") + "MemberVar" + (isprivate ? "Private" : "") + (noCtor ? "NoCtor" : ""); |
| 1188 | const std::string verbose {message + " Member variables of native types, pointers, or references are left uninitialized when the class is instantiated. That may cause bugs or undefined behavior."}; |
| 1189 | reportError(tok, Severity::warning, id, "$symbol:" + classname + "::" + varname + '\n' + message + '\n' + verbose, CWE398, inconclusive ? Certainty::inconclusive : Certainty::normal); |
| 1190 | } |
| 1191 | |
| 1192 | void CheckClassImpl::uninitVarError(const Token *tok, const std::string &classname, const std::string &varname) |
| 1193 | { |
no test coverage detected