diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5a218261485..9926b268ca5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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(); } diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 01275ac74ab..6159b2ad49f 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -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() {