@@ -372,7 +372,7 @@ void CheckClass::constructors()
372372
373373 const Variable& var = *usage.var ;
374374 if (diagVars.count (&var) == 0 )
375- uninitVarError (scope->bodyStart , false , FunctionType::eConstructor, var.scope ()->className , var.name (), false , false );
375+ uninitVarError (scope->bodyStart , false , FunctionType::eConstructor, var.scope ()->className , var.name (), false , false , true );
376376 }
377377 }
378378 }
@@ -1167,17 +1167,22 @@ void CheckClass::noExplicitConstructorError(const Token *tok, const std::string
11671167 reportError (tok, Severity::style, " noExplicitConstructor" , " $symbol:" + classname + ' \n ' + message + ' \n ' + verbose, CWE398, Certainty::normal);
11681168}
11691169
1170- void CheckClass::uninitVarError (const Token *tok, bool isprivate, FunctionType functionType, const std::string &classname, const std::string &varname, bool derived, bool inconclusive)
1170+ void CheckClass::uninitVarError (const Token *tok, bool isprivate, FunctionType functionType, const std::string &classname, const std::string &varname, bool derived, bool inconclusive, bool noCtor )
11711171{
1172- std::string ctor;
1173- if (functionType == FunctionType::eCopyConstructor)
1174- ctor = " copy " ;
1175- else if (functionType == FunctionType::eMoveConstructor)
1176- ctor = " move " ;
1177- std::string message (" Member variable '$symbol' is not initialized in the " + ctor + " constructor." );
1172+ std::string message (" Member variable '$symbol' " );
1173+ if (noCtor)
1174+ message += " has no initializer." ;
1175+ else {
1176+ message += " is not initialized in the " ;
1177+ if (functionType == FunctionType::eCopyConstructor)
1178+ message += " copy " ;
1179+ else if (functionType == FunctionType::eMoveConstructor)
1180+ message += " move " ;
1181+ message += " constructor." ;
1182+ }
11781183 if (derived)
11791184 message += " Maybe it should be initialized directly in the class " + classname + " ?" ;
1180- std::string id = std::string (" uninit" ) + (derived ? " Derived" : " " ) + " MemberVar" + (isprivate ? " Private" : " " );
1185+ std::string id = std::string (" uninit" ) + (derived ? " Derived" : " " ) + " MemberVar" + (isprivate ? " Private" : " " ) + (noCtor ? " NoCtor " : " " ) ;
11811186 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." };
11821187 reportError (tok, Severity::warning, id, " $symbol:" + classname + " ::" + varname + ' \n ' + message + ' \n ' + verbose, CWE398, inconclusive ? Certainty::inconclusive : Certainty::normal);
11831188}
0 commit comments