Skip to content

Commit

Permalink
Fix #13368 Crash in simplifyTypedefCpp() (II) (#7070)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Dec 5, 2024
1 parent 640f82d commit 34a6266
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2079,7 +2079,7 @@ void Tokenizer::simplifyTypedefCpp()
for (const std::string &p : pointers)
// cppcheck-suppress useStlAlgorithm
tok2 = simplifyTypedefInsertToken(tok2, p, location);
if (constTok) {
if (constTok && !functionPtr) {
tok2 = simplifyTypedefInsertToken(tok2, "const", location);
constTok->deleteThis();
}
Expand Down
6 changes: 6 additions & 0 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4500,6 +4500,12 @@ class TestSimplifyTypedef : public TestFixture {
"void f(const P p);\n";
ASSERT_EQUALS("struct S_ { } ; void f ( struct S_ * const p ) ;", // don't crash
tok(code));

const char code2[] = "struct S;\n"
"typedef S& (S::* P)(const S&);\n"
"void f(const P);\n";
ASSERT_EQUALS("struct S ; void f ( const S & ( S :: * ) ( const S & ) ) ;", // don't crash
tok(code2));
}

void typedefInfo1() {
Expand Down

0 comments on commit 34a6266

Please sign in to comment.