Skip to content

Commit 360741f

Browse files
committed
fix #13954
1 parent f1138a8 commit 360741f

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

lib/checkunusedvar.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,9 @@ void CheckUnusedVar::checkStructMemberUsage()
15751575
if (isInherited && !var.isPrivate())
15761576
continue;
15771577

1578+
if (var.nameToken() && var.nameToken()->isAttributeUnused())
1579+
continue;
1580+
15781581
if (mTokenizer->isVarUsedInTemplate(var.declarationId()))
15791582
continue;
15801583

lib/tokenize.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9970,12 +9970,8 @@ void Tokenizer::simplifyAt()
99709970
// Simplify bitfields
99719971
void Tokenizer::simplifyBitfields()
99729972
{
9973-
bool goback = false;
9973+
std::size_t anonymousBitfieldCounter = 0;
99749974
for (Token *tok = list.front(); tok; tok = tok->next()) {
9975-
if (goback) {
9976-
goback = false;
9977-
tok = tok->previous();
9978-
}
99799975
Token *last = nullptr;
99809976

99819977
if (Token::simpleMatch(tok, "for ("))
@@ -10025,8 +10021,15 @@ void Tokenizer::simplifyBitfields()
1002510021
}
1002610022
} else if (Token::Match(typeTok, "%type% : %num%|%bool% ;") &&
1002710023
typeTok->str() != "default") {
10028-
tok->deleteNext(4 + tokDistance(tok, typeTok) - 1);
10029-
goback = true;
10024+
const std::size_t id = anonymousBitfieldCounter++;
10025+
const std::string name = "__cppcheck_anon_bit_field_" + std::to_string(id) + "__";
10026+
Token *newTok = typeTok->insertToken(name);
10027+
newTok->isAttributeUnused(true);
10028+
if (newTok->tokAt(2)->isBoolean())
10029+
newTok->setBits(static_cast<unsigned char>(newTok->tokAt(2)->str() == "true"));
10030+
else
10031+
newTok->setBits(static_cast<unsigned char>(MathLib::toBigNumber(newTok->tokAt(2))));
10032+
newTok->deleteNext(2);
1003010033
}
1003110034

1003210035
if (last && last->str() == ",") {

0 commit comments

Comments
 (0)