Skip to content

Commit 29e2a7e

Browse files
Fix #11640 internalAstError with typedef matching member function [regression] (#4981)
1 parent 6031bed commit 29e2a7e

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ namespace {
895895
bool canReplace(const Token* tok) {
896896
if (mNameToken == tok)
897897
return false;
898-
if (!Token::Match(tok->previous(), "%name%|;|{|}|(|,|<") && !Token::Match(tok, "%name% ("))
898+
if (!Token::Match(tok->previous(), "%name%|;|{|}|(|,|<") && !Token::Match(tok->previous(), "!!. %name% ("))
899899
return false;
900900
if (!Token::Match(tok, "%name% %name%|*|&|&&|;|(|)|,|::")) {
901901
if (Token::Match(tok->previous(), "( %name% =") && Token::Match(tok->linkAt(-1), ") %name%|{") && !tok->tokAt(-2)->isKeyword())

test/testsimplifytypedef.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class TestSimplifyTypedef : public TestFixture {
5757
TEST_CASE(c2);
5858
TEST_CASE(canreplace1);
5959
TEST_CASE(canreplace2);
60+
TEST_CASE(canreplace3);
6061
TEST_CASE(cconst);
6162
TEST_CASE(cstruct1);
6263
TEST_CASE(cstruct2);
@@ -342,6 +343,17 @@ class TestSimplifyTypedef : public TestFixture {
342343
ASSERT_EQUALS("void f ( ) { dostuff ( entry * y < z ) ; }", simplifyTypedefC(code3));
343344
}
344345

346+
void canreplace3() {
347+
const char code1[] = "typedef char* c_str;\n" // #11640
348+
"struct S {\n"
349+
" const char* g() const {\n"
350+
" return s.c_str();\n"
351+
" }\n"
352+
" std::string s;\n"
353+
"};\n";
354+
ASSERT_EQUALS("struct S { const char * g ( ) const { return s . c_str ( ) ; } std :: string s ; } ;", simplifyTypedefC(code1));
355+
}
356+
345357
void cconst() {
346358
const char code1[] = "typedef void* HWND;\n"
347359
"const HWND x;";

0 commit comments

Comments
 (0)