Skip to content

Commit 34a6266

Browse files
Fix #13368 Crash in simplifyTypedefCpp() (II) (#7070)
1 parent 640f82d commit 34a6266

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2079,7 +2079,7 @@ void Tokenizer::simplifyTypedefCpp()
20792079
for (const std::string &p : pointers)
20802080
// cppcheck-suppress useStlAlgorithm
20812081
tok2 = simplifyTypedefInsertToken(tok2, p, location);
2082-
if (constTok) {
2082+
if (constTok && !functionPtr) {
20832083
tok2 = simplifyTypedefInsertToken(tok2, "const", location);
20842084
constTok->deleteThis();
20852085
}

test/testsimplifytypedef.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4500,6 +4500,12 @@ class TestSimplifyTypedef : public TestFixture {
45004500
"void f(const P p);\n";
45014501
ASSERT_EQUALS("struct S_ { } ; void f ( struct S_ * const p ) ;", // don't crash
45024502
tok(code));
4503+
4504+
const char code2[] = "struct S;\n"
4505+
"typedef S& (S::* P)(const S&);\n"
4506+
"void f(const P);\n";
4507+
ASSERT_EQUALS("struct S ; void f ( const S & ( S :: * ) ( const S & ) ) ;", // don't crash
4508+
tok(code2));
45034509
}
45044510

45054511
void typedefInfo1() {

0 commit comments

Comments
 (0)