From 09bdc8c95c9d7a4d55970fcd685344fecf0d624a Mon Sep 17 00:00:00 2001 From: chrchr Date: Tue, 18 Apr 2023 15:42:14 +0200 Subject: [PATCH] Fix #11640 internalAstError with typedef matching member function [regression] --- lib/tokenize.cpp | 2 +- test/testsimplifytypedef.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index e1d4b9f423f..b0ea4ed6fc1 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -895,7 +895,7 @@ namespace { bool canReplace(const Token* tok) { if (mNameToken == tok) return false; - if (!Token::Match(tok->previous(), "%name%|;|{|}|(|,|<") && !Token::Match(tok, "%name% (")) + if (!Token::Match(tok->previous(), "%name%|;|{|}|(|,|<") && !Token::Match(tok->previous(), "!!. %name% (")) return false; if (!Token::Match(tok, "%name% %name%|*|&|&&|;|(|)|,|::")) { if (Token::Match(tok->previous(), "( %name% =") && Token::Match(tok->linkAt(-1), ") %name%|{") && !tok->tokAt(-2)->isKeyword()) diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index ad7164acd28..69205242feb 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -57,6 +57,7 @@ class TestSimplifyTypedef : public TestFixture { TEST_CASE(c2); TEST_CASE(canreplace1); TEST_CASE(canreplace2); + TEST_CASE(canreplace3); TEST_CASE(cconst); TEST_CASE(cstruct1); TEST_CASE(cstruct2); @@ -342,6 +343,17 @@ class TestSimplifyTypedef : public TestFixture { ASSERT_EQUALS("void f ( ) { dostuff ( entry * y < z ) ; }", simplifyTypedefC(code3)); } + void canreplace3() { + const char code1[] = "typedef char* c_str;\n" // #11640 + "struct S {\n" + " const char* g() const {\n" + " return s.c_str();\n" + " }\n" + " std::string s;\n" + "};\n"; + ASSERT_EQUALS("struct S { const char * g ( ) const { return s . c_str ( ) ; } std :: string s ; } ;", simplifyTypedefC(code1)); + } + void cconst() { const char code1[] = "typedef void* HWND;\n" "const HWND x;";