Skip to content

Commit 9126d20

Browse files
committed
fix #13954
1 parent 62de5bd commit 9126d20

2 files changed

Lines changed: 13 additions & 2 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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9970,6 +9970,7 @@ void Tokenizer::simplifyAt()
99709970
// Simplify bitfields
99719971
void Tokenizer::simplifyBitfields()
99729972
{
9973+
std::size_t anonymousBitfieldCounter = 0;
99739974
bool goback = false;
99749975
for (Token *tok = list.front(); tok; tok = tok->next()) {
99759976
if (goback) {
@@ -10025,8 +10026,15 @@ void Tokenizer::simplifyBitfields()
1002510026
}
1002610027
} else if (Token::Match(typeTok, "%type% : %num%|%bool% ;") &&
1002710028
typeTok->str() != "default") {
10028-
tok->deleteNext(4 + tokDistance(tok, typeTok) - 1);
10029-
goback = true;
10029+
const std::size_t id = anonymousBitfieldCounter++;
10030+
const std::string name = "__cppcheck_anon_bit_field_" + std::to_string(id) + "__";
10031+
Token *newTok = typeTok->insertToken(name);
10032+
newTok->isAttributeUnused(true);
10033+
if (newTok->tokAt(2)->isBoolean())
10034+
newTok->setBits(static_cast<unsigned char>(newTok->tokAt(2)->str() == "true"));
10035+
else
10036+
newTok->setBits(static_cast<unsigned char>(MathLib::toBigNumber(newTok->tokAt(2))));
10037+
newTok->deleteNext(2);
1003010038
}
1003110039

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

0 commit comments

Comments
 (0)