Skip to content

Commit b77f655

Browse files
committed
fix #14130
1 parent fc68f7b commit b77f655

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

lib/checkclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
}

lib/checkunusedvar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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()))

lib/symboldatabase.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff 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

lib/tokenize.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9542,7 +9542,23 @@ void Tokenizer::simplifyCPPAttribute()
95429542
Token* head = skipCPPOrAlignAttribute(tok)->next();
95439543
while (isCPPAttribute(head) || isAlignAttribute(head))
95449544
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+
}
95469562
} else if (Token::findsimplematch(tok->tokAt(2), "unused", tok->link())) {
95479563
Token* head = skipCPPOrAlignAttribute(tok)->next();
95489564
while (isCPPAttribute(head) || isAlignAttribute(head))

0 commit comments

Comments
 (0)