@@ -972,13 +972,6 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
972972 } else if (varid1 && Token::Match (tok, " %varid% ." , varid1)) {
973973 variables.read (varid1, tok);
974974 variables.write (varid1, start);
975- } else if (var &&
976- var->mType == Variables::pointer &&
977- Token::Match (tok, " %name% ;" ) &&
978- tok->varId () == 0 &&
979- tok->hasKnownIntValue () &&
980- tok->values ().front ().intvalue == 0 ) {
981- variables.use (varid1, tok);
982975 } else {
983976 variables.write (varid1, tok);
984977 }
@@ -1156,6 +1149,15 @@ void CheckUnusedVar::checkFunctionVariableUsage()
11561149 // Parse all executing scopes..
11571150 const SymbolDatabase *symbolDatabase = mTokenizer ->getSymbolDatabase ();
11581151
1152+ auto reportLibraryCfgError = [this ](const Token* tok, const std::string& typeName) {
1153+ if (mSettings ->checkLibrary && mSettings ->severity .isEnabled (Severity::information)) {
1154+ reportError (tok,
1155+ Severity::information,
1156+ " checkLibraryCheckType" ,
1157+ " --check-library: Provide <type-checks><unusedvar> configuration for " + typeName);
1158+ }
1159+ };
1160+
11591161 // only check functions
11601162 for (const Scope * scope : symbolDatabase->functionScopes ) {
11611163 // Bailout when there are lambdas or inline functions
@@ -1281,12 +1283,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
12811283 const Token* scopeEnd = getEndOfExprScope (expr, scope, /* smallest*/ false );
12821284 if (fwdAnalysis.unusedValue (expr, start, scopeEnd)) {
12831285 if (!bailoutTypeName.empty () && bailoutTypeName != " auto" ) {
1284- if (mSettings ->checkLibrary && mSettings ->severity .isEnabled (Severity::information)) {
1285- reportError (tok,
1286- Severity::information,
1287- " checkLibraryCheckType" ,
1288- " --check-library: Provide <type-checks><unusedvar> configuration for " + bailoutTypeName);
1289- }
1286+ reportLibraryCfgError (tok, bailoutTypeName);
12901287 continue ;
12911288 }
12921289
@@ -1339,6 +1336,26 @@ void CheckUnusedVar::checkFunctionVariableUsage()
13391336 // variable has been read but not written
13401337 else if (!usage._write && !usage._allocateMemory && var && !var->isStlType () && !isEmptyType (var->type ()))
13411338 unassignedVariableError (usage._var ->nameToken (), varname);
1339+ else if (!usage._var ->isMaybeUnused () && !usage._modified && !usage._read && var) {
1340+ if (usage._lastAccess ->linenr () == var->nameToken ()->linenr () && var->nameToken ()->next ()->isSplittedVarDeclEq ()) {
1341+ bool error = true ;
1342+ if (mTokenizer ->isCPP () && var->isClass () &&
1343+ (!var->valueType () || var->valueType ()->type == ValueType::Type::UNKNOWN_TYPE )) {
1344+ const std::string typeName = var->getTypeName ();
1345+ switch (mSettings ->library .getTypeCheck (" unusedvar" , typeName)) {
1346+ case Library::TypeCheck::def:
1347+ reportLibraryCfgError (var->nameToken (), typeName);
1348+ break ;
1349+ case Library::TypeCheck::check:
1350+ break ;
1351+ case Library::TypeCheck::suppress:
1352+ error = false ;
1353+ }
1354+ }
1355+ if (error)
1356+ unreadVariableError (usage._var ->nameToken (), varname, false );
1357+ }
1358+ }
13421359 }
13431360 }
13441361}
0 commit comments