Skip to content

Commit 7515c3a

Browse files
authored
fix #13733: Bitfield not simplified when using type in namespace (danmar#7718)
1 parent b067f37 commit 7515c3a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/tokenize.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10022,6 +10022,10 @@ void Tokenizer::simplifyBitfields()
1002210022
Token* typeTok = tok->next();
1002310023
while (Token::Match(typeTok, "const|volatile"))
1002410024
typeTok = typeTok->next();
10025+
if (Token::Match(typeTok, ":: %name%"))
10026+
typeTok = typeTok->next();
10027+
while (Token::Match(typeTok, "%name% :: %name%"))
10028+
typeTok = typeTok->tokAt(2);
1002510029
if (Token::Match(typeTok, "%type% %name% :") &&
1002610030
!Token::Match(tok->next(), "case|public|protected|private|class|struct") &&
1002710031
!Token::simpleMatch(tok->tokAt(2), "default :")) {

test/testtokenize.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ class TestTokenizer : public TestFixture {
305305
TEST_CASE(bitfields16); // Save bitfield bit count
306306
TEST_CASE(bitfields17);
307307
TEST_CASE(bitfields18);
308+
TEST_CASE(bitfields19); // ticket #13733
309+
TEST_CASE(bitfields20);
308310

309311
TEST_CASE(simplifyNamespaceStd);
310312

@@ -4858,6 +4860,16 @@ class TestTokenizer : public TestFixture {
48584860
ASSERT_EQUALS("[test.cpp:1:29]: (warning) Bit-field size exceeds max number of bits 32767 [tooLargeBitField]\n", errout_str());
48594861
}
48604862

4863+
void bitfields19() {
4864+
const char code[] = "struct S { volatile std::uint32_t a : 10; };";
4865+
ASSERT_EQUALS("struct S { volatile std :: uint32_t a ; } ;", tokenizeAndStringify(code));
4866+
}
4867+
4868+
void bitfields20() {
4869+
const char code[] = "struct S { volatile ::uint32_t a : 10; };";
4870+
ASSERT_EQUALS("struct S { volatile :: uint32_t a ; } ;", tokenizeAndStringify(code));
4871+
}
4872+
48614873
void simplifyNamespaceStd() {
48624874
const char *expected;
48634875

0 commit comments

Comments
 (0)