File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1338,7 +1338,7 @@ void CheckClass::privateFunctions()
13381338
13391339 while (!privateFuncs.empty ()) {
13401340 const auto & pf = privateFuncs.front ();
1341- if (pf->retDef && pf-> retDef ->isAttributeMaybeUnused ()) {
1341+ if (pf->token ->isAttributeMaybeUnused ()) {
13421342 privateFuncs.pop_front ();
13431343 continue ;
13441344 }
Original file line number Diff line number Diff line change @@ -1606,7 +1606,7 @@ void CheckUnusedVar::checkStructMemberUsage()
16061606 if (isInherited && !var.isPrivate ())
16071607 continue ;
16081608
1609- if (!var.nameToken () || var.nameToken ()->isAttributeUnused () || var.nameToken ()->isAnonymous ())
1609+ if (!var.nameToken () || var.nameToken ()->isAttributeUnused () || var.nameToken ()->isAttributeMaybeUnused () || var. nameToken ()-> isAnonymous ())
16101610 continue ;
16111611
16121612 if (mTokenizer ->isVarUsedInTemplate (var.declarationId ()))
Original file line number Diff line number Diff line change @@ -2357,8 +2357,11 @@ void Variable::evaluate(const Settings& settings)
23572357 const Library & lib = settings.library ;
23582358
23592359 bool isContainer = false ;
2360- if (mNameToken )
2360+ if (mNameToken ) {
23612361 setFlag (fIsArray , arrayDimensions (settings, isContainer));
2362+ setFlag (fIsMaybeUnused , mNameToken ->isAttributeMaybeUnused ());
2363+ }
2364+
23622365
23632366 if (mTypeStartToken )
23642367 setValueType (ValueType::parseDecl (mTypeStartToken ,settings));
@@ -2395,10 +2398,6 @@ void Variable::evaluate(const Settings& settings)
23952398 setFlag (fIsReference , true ); // Set also fIsReference
23962399 }
23972400
2398- if (tok->isAttributeMaybeUnused ()) {
2399- setFlag (fIsMaybeUnused , true );
2400- }
2401-
24022401 if (tok->str () == " <" && tok->link ())
24032402 tok = tok->link ();
24042403 else
Original file line number Diff line number Diff line change @@ -9550,9 +9550,27 @@ void Tokenizer::simplifyCPPAttribute()
95509550 Token* head = skipCPPOrAlignAttribute (tok)->next ();
95519551 while (isCPPAttribute (head) || isAlignAttribute (head))
95529552 head = skipCPPOrAlignAttribute (head)->next ();
9553+
95539554 if (!head)
95549555 syntaxError (tok);
9555- head->isAttributeMaybeUnused (true );
9556+
9557+ while (Token::Match (head->next (), " %name%|*|&|&&|const|static|inline|volatile" ))
9558+ head = head->next ();
9559+ if (Token::Match (head, " %name%" ) && !Token::Match (head, " auto [" ))
9560+ head->isAttributeMaybeUnused (true );
9561+ else if (Token::Match (tok->previous (), " %name%" ) && Token::Match (tok->link (), " ] [;={]" )) {
9562+ tok->previous ()->isAttributeMaybeUnused (true );
9563+ } else {
9564+ if (Token::simpleMatch (head->next (), " [" )) {
9565+ head = head->next ();
9566+ const Token *end = head->link ();
9567+ for (head = head->next (); end && head != end; head = head->next ()) {
9568+ if (Token::Match (head, " %name%" )) {
9569+ head->isAttributeMaybeUnused (true );
9570+ }
9571+ }
9572+ }
9573+ }
95569574 } else if (Token::findsimplematch (tok->tokAt (2 ), " unused" , tok->link ())) {
95579575 Token* head = skipCPPOrAlignAttribute (tok)->next ();
95589576 while (isCPPAttribute (head) || isAlignAttribute (head))
You can’t perform that action at this time.
0 commit comments