File tree Expand file tree Collapse file tree 4 files changed +23
-8
lines changed Expand file tree Collapse file tree 4 files changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -1338,7 +1338,7 @@ void CheckClass::privateFunctions()
1338
1338
1339
1339
while (!privateFuncs.empty ()) {
1340
1340
const auto & pf = privateFuncs.front ();
1341
- if (pf->retDef && pf-> retDef ->isAttributeMaybeUnused ()) {
1341
+ if (pf->token ->isAttributeMaybeUnused ()) {
1342
1342
privateFuncs.pop_front ();
1343
1343
continue ;
1344
1344
}
Original file line number Diff line number Diff line change @@ -1606,7 +1606,7 @@ void CheckUnusedVar::checkStructMemberUsage()
1606
1606
if (isInherited && !var.isPrivate ())
1607
1607
continue ;
1608
1608
1609
- if (!var.nameToken () || var.nameToken ()->isAttributeUnused () || var.nameToken ()->isAnonymous ())
1609
+ if (!var.nameToken () || var.nameToken ()->isAttributeUnused () || var.nameToken ()->isAttributeMaybeUnused () || var. nameToken ()-> isAnonymous ())
1610
1610
continue ;
1611
1611
1612
1612
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)
2357
2357
const Library & lib = settings.library ;
2358
2358
2359
2359
bool isContainer = false ;
2360
- if (mNameToken )
2360
+ if (mNameToken ) {
2361
2361
setFlag (fIsArray , arrayDimensions (settings, isContainer));
2362
+ setFlag (fIsMaybeUnused , mNameToken ->isAttributeMaybeUnused ());
2363
+ }
2364
+
2362
2365
2363
2366
if (mTypeStartToken )
2364
2367
setValueType (ValueType::parseDecl (mTypeStartToken ,settings));
@@ -2395,10 +2398,6 @@ void Variable::evaluate(const Settings& settings)
2395
2398
setFlag (fIsReference , true ); // Set also fIsReference
2396
2399
}
2397
2400
2398
- if (tok->isAttributeMaybeUnused ()) {
2399
- setFlag (fIsMaybeUnused , true );
2400
- }
2401
-
2402
2401
if (tok->str () == " <" && tok->link ())
2403
2402
tok = tok->link ();
2404
2403
else
Original file line number Diff line number Diff line change @@ -9542,7 +9542,23 @@ void Tokenizer::simplifyCPPAttribute()
9542
9542
Token* head = skipCPPOrAlignAttribute (tok)->next ();
9543
9543
while (isCPPAttribute (head) || isAlignAttribute (head))
9544
9544
head = skipCPPOrAlignAttribute (head)->next ();
9545
- head->isAttributeMaybeUnused (true );
9545
+ while (Token::Match (head->next (), " %name%|*|&|&&|const|static|inline|volatile" ))
9546
+ head = head->next ();
9547
+ if (Token::Match (head, " %name%" ) && !Token::Match (head, " auto [" ))
9548
+ head->isAttributeMaybeUnused (true );
9549
+ else if (Token::Match (tok->previous (), " %name%" ) && Token::Match (tok->link (), " ] [;={]" )) {
9550
+ tok->previous ()->isAttributeMaybeUnused (true );
9551
+ } else {
9552
+ if (Token::simpleMatch (head->next (), " [" )) {
9553
+ head = head->next ();
9554
+ const Token *end = head->link ();
9555
+ for (head = head->next (); end && head != end; head = head->next ()) {
9556
+ if (Token::Match (head, " %name%" )) {
9557
+ head->isAttributeMaybeUnused (true );
9558
+ }
9559
+ }
9560
+ }
9561
+ }
9546
9562
} else if (Token::findsimplematch (tok->tokAt (2 ), " unused" , tok->link ())) {
9547
9563
Token* head = skipCPPOrAlignAttribute (tok)->next ();
9548
9564
while (isCPPAttribute (head) || isAlignAttribute (head))
You can’t perform that action at this time.
0 commit comments