Fix #11640 internalAstError with typedef matching member function [regression] (#4981)

This commit is contained in:
chrchr-github 2023-04-18 18:38:16 +02:00 committed by GitHub
parent 6031bed5a2
commit 29e2a7ed34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -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())

View File

@ -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;";