From 29e2a7ed3447dce68828a349851d40655e62c5f7 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 18 Apr 2023 18:38:16 +0200 Subject: [PATCH] Fix #11640 internalAstError with typedef matching member function [regression] (#4981) --- 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 e1d4b9f42..b0ea4ed6f 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 ad7164acd..69205242f 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -57,6 +57,7 @@ private: 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 @@ private: 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;";