Skip to content

Commit 5dbcde4

Browse files
committed
change string of token inserted for unnamed bit-fields
1 parent f2b9e1c commit 5dbcde4

5 files changed

Lines changed: 15 additions & 15 deletions

File tree

lib/checkclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ void CheckClass::constructors()
231231
if (usage.assign || usage.init || var.isStatic())
232232
continue;
233233

234-
if (var.nameToken() && var.nameToken()->isAnonymousBitfield())
234+
if (var.nameToken() && var.nameToken()->isAnonymous())
235235
continue;
236236

237237
if (var.valueType() && var.valueType()->pointer == 0 && var.type() && var.type()->needInitialization == Type::NeedInitialization::False && var.type()->derivedFrom.empty())

lib/checkunusedvar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,7 @@ void CheckUnusedVar::checkStructMemberUsage()
15751575
if (isInherited && !var.isPrivate())
15761576
continue;
15771577

1578-
if (var.nameToken() && (var.nameToken()->isAttributeUnused() || var.nameToken()->isAnonymousBitfield()))
1578+
if (var.nameToken() && (var.nameToken()->isAttributeUnused() || var.nameToken()->isAnonymous()))
15791579
continue;
15801580

15811581
if (mTokenizer->isVarUsedInTemplate(var.declarationId()))

lib/token.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -742,11 +742,11 @@ class CPPCHECKLIB Token {
742742
setFlag(fIsInitBracket, b);
743743
}
744744

745-
bool isAnonymousBitfield() const {
746-
return getFlag(fIsAnonymousBitfield);
745+
bool isAnonymous() const {
746+
return getFlag(fIsAnonymous);
747747
}
748-
void isAnonymousBitfield(bool b) {
749-
setFlag(fIsAnonymousBitfield, b);
748+
void isAnonymous(bool b) {
749+
setFlag(fIsAnonymous, b);
750750
}
751751

752752
// cppcheck-suppress unusedFunction
@@ -1433,7 +1433,7 @@ class CPPCHECKLIB Token {
14331433
fIsFinalType = (1ULL << 42), // Is this a type with final specifier
14341434
fIsInitComma = (1ULL << 43), // Is this comma located inside some {..}. i.e: {1,2,3,4}
14351435
fIsInitBracket = (1ULL << 44), // Is this bracket used as a part of variable initialization i.e: int a{5}, b(2);
1436-
fIsAnonymousBitfield = (1ULL << 45), // Is this a token added for an unnamed bit-field
1436+
fIsAnonymous = (1ULL << 45), // Is this a token added for an unnamed bit-field
14371437
};
14381438

14391439
enum : std::uint8_t {

lib/tokenize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10037,9 +10037,9 @@ void Tokenizer::simplifyBitfields()
1003710037
} else if (Token::Match(typeTok, "%type% : %num%|%bool% ;") &&
1003810038
typeTok->str() != "default") {
1003910039
const std::size_t id = anonymousBitfieldCounter++;
10040-
const std::string name = "__cppcheck_anon_bit_field_" + std::to_string(id) + "__";
10040+
const std::string name = "anonymous@" + std::to_string(id);
1004110041
Token *newTok = typeTok->insertToken(name);
10042-
newTok->isAnonymousBitfield(true);
10042+
newTok->isAnonymous(true);
1004310043
if (newTok->tokAt(2)->isBoolean())
1004410044
newTok->setBits(newTok->strAt(2) == "true");
1004510045
else

test/testtokenize.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4724,7 +4724,7 @@ class TestTokenizer : public TestFixture {
47244724
ASSERT_EQUALS("struct RGB { unsigned int r ; unsigned int g ; unsigned int b ; } ;", tokenizeAndStringify(code1));
47254725

47264726
const char code2[] = "struct A { int a : 3; int : 3; int c : 3; };";
4727-
ASSERT_EQUALS("struct A { int a ; int __cppcheck_anon_bit_field_0__ ; int c ; } ;", tokenizeAndStringify(code2));
4727+
ASSERT_EQUALS("struct A { int a ; int anonymous@0 ; int c ; } ;", tokenizeAndStringify(code2));
47284728

47294729
const char code3[] = "struct A { virtual void f() {} int f1 : 1; };";
47304730
ASSERT_EQUALS("struct A { virtual void f ( ) { } int f1 ; } ;", tokenizeAndStringify(code3));
@@ -4738,7 +4738,7 @@ class TestTokenizer : public TestFixture {
47384738
ASSERT_EQUALS("struct A { bool b ; bool c ; } ;", tokenizeAndStringify(code2));
47394739

47404740
const char code3[] = "struct A { bool : true; };";
4741-
ASSERT_EQUALS("struct A { bool __cppcheck_anon_bit_field_0__ ; } ;", tokenizeAndStringify(code3));
4741+
ASSERT_EQUALS("struct A { bool anonymous@0 ; } ;", tokenizeAndStringify(code3));
47424742
}
47434743

47444744
void bitfields7() { // ticket #1987
@@ -4789,7 +4789,7 @@ class TestTokenizer : public TestFixture {
47894789

47904790
void bitfields12() { // ticket #3485 (segmentation fault)
47914791
const char code[] = "{a:1;};\n";
4792-
ASSERT_EQUALS("{ a __cppcheck_anon_bit_field_0__ ; } ;", tokenizeAndStringify(code));
4792+
ASSERT_EQUALS("{ a anonymous@0 ; } ;", tokenizeAndStringify(code));
47934793
}
47944794

47954795
void bitfields13() { // ticket #3502 (segmentation fault)
@@ -4829,9 +4829,9 @@ class TestTokenizer : public TestFixture {
48294829
"};\n";
48304830
const char expected[] = "struct S {\n"
48314831
"volatile uint32_t a ;\n"
4832-
"volatile uint32_t __cppcheck_anon_bit_field_0__ ;\n"
4832+
"volatile uint32_t anonymous@0 ;\n"
48334833
"volatile uint32_t b ;\n"
4834-
"volatile uint32_t __cppcheck_anon_bit_field_1__ ;\n"
4834+
"volatile uint32_t anonymous@1 ;\n"
48354835
"} ;";
48364836
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
48374837

@@ -4841,7 +4841,7 @@ class TestTokenizer : public TestFixture {
48414841
"};\n";
48424842
const char expected2[] = "struct S {\n"
48434843
"const volatile uint32_t a ;\n"
4844-
"const volatile uint32_t __cppcheck_anon_bit_field_0__ ;\n"
4844+
"const volatile uint32_t anonymous@0 ;\n"
48454845
"} ;";
48464846
ASSERT_EQUALS(expected2, tokenizeAndStringify(code2));
48474847
}

0 commit comments

Comments
 (0)