Skip to content

Commit

Permalink
Don't modify mRangeType
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jan 4, 2024
1 parent 1f9316d commit 5a15ce2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 6 additions & 3 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,10 +822,13 @@ namespace {
}

// don't add class|struct|union in inheritance list
if (Token::Match(tok->previous(), "public|private|protected") && Token::Match(mRangeType.first, "const| class|struct|union"))
mRangeType.first = mRangeType.first->tokAt(mRangeType.first->str() == "const" ? 2 : 1);
auto rangeType = mRangeType;
if (Token::Match(tok->previous(), "public|private|protected")) {
while (Token::Match(rangeType.first, "const|class|struct|union"))
rangeType.first = rangeType.first->next();
}

Token* const tok2 = insertTokens(tok, mRangeType);
Token* const tok2 = insertTokens(tok, rangeType);
Token* const tok3 = insertTokens(tok2, mRangeTypeQualifiers);

Token *after = tok3;
Expand Down
7 changes: 4 additions & 3 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1622,13 +1622,14 @@ class TestSimplifyTypedef : public TestFixture {
}

{
const char code[] = "struct B {};\n" // #12141
const char code[] = "struct B {};\n"
"typedef const struct B CB;\n"
"namespace N {\n"
" struct D : public CB {};\n"
"}\n";
"}\n"
"CB cb;\n";

const char expected[] = "struct B { } ; namespace N { struct D : public B { } ; }";
const char expected[] = "struct B { } ; namespace N { struct D : public B { } ; } const struct B cb ;";
ASSERT_EQUALS(expected, tok(code));
ASSERT_EQUALS("", errout.str());
}
Expand Down

0 comments on commit 5a15ce2

Please sign in to comment.