@@ -1437,7 +1437,7 @@ void CheckUnusedVar::checkStructMemberUsage()
14371437 const SymbolDatabase *symbolDatabase = mTokenizer ->getSymbolDatabase ();
14381438
14391439 for (const Scope &scope : symbolDatabase->scopeList ) {
1440- if (scope.type != Scope::eStruct && scope.type != Scope::eUnion)
1440+ if (scope.type != Scope::eStruct && scope.type != Scope::eClass && scope. type != Scope:: eUnion)
14411441 continue ;
14421442
14431443 if (scope.bodyStart ->fileIndex () != 0 || scope.className .empty ())
@@ -1521,16 +1521,21 @@ void CheckUnusedVar::checkStructMemberUsage()
15211521 break ;
15221522 }
15231523 }
1524- if (!use)
1525- unusedStructMemberError (var.nameToken (), scope.className , var.name (), scope.type == Scope::eUnion);
1524+ if (!use) {
1525+ std::string prefix = " struct" ;
1526+ if (scope.type == Scope::ScopeType::eClass)
1527+ prefix = " class" ;
1528+ else if (scope.type == Scope::ScopeType::eUnion)
1529+ prefix = " union" ;
1530+ unusedStructMemberError (var.nameToken (), scope.className , var.name (), prefix);
1531+ }
15261532 }
15271533 }
15281534}
15291535
1530- void CheckUnusedVar::unusedStructMemberError (const Token * tok, const std::string & structname, const std::string & varname, bool isUnion )
1536+ void CheckUnusedVar::unusedStructMemberError (const Token* tok, const std::string& structname, const std::string& varname, const std::string& prefix )
15311537{
1532- const std::string prefix = isUnion ? " union member " : " struct member " ;
1533- reportError (tok, Severity::style, " unusedStructMember" , " $symbol:" + structname + " ::" + varname + ' \n ' + prefix + " '$symbol' is never used." , CWE563, Certainty::normal);
1538+ reportError (tok, Severity::style, " unusedStructMember" , " $symbol:" + structname + " ::" + varname + ' \n ' + prefix + " member '$symbol' is never used." , CWE563, Certainty::normal);
15341539}
15351540
15361541bool CheckUnusedVar::isRecordTypeWithoutSideEffects (const Type* type)
0 commit comments