Fix #11981 internalAstError with using declaration (#5446)

This commit is contained in:
chrchr-github 2023-09-14 12:14:08 +02:00 committed by GitHub
parent 775af5ec70
commit 5a21851bb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -3236,9 +3236,18 @@ bool Tokenizer::simplifyUsing()
} }
} }
// just replace simple type aliases // Is this a "T()" expression where T is a pointer type?
TokenList::copyTokens(tok1, start, usingEnd->previous()); if (Token::Match(tok1, "%name% ( )") && !pointers.empty()) {
tok1->deleteThis(); Token* tok2 = tok1->linkAt(1);
tok1->deleteThis();
TokenList::copyTokens(tok1, start, usingEnd->previous());
tok2->insertToken("0");
after = tok2->next();
}
else { // just replace simple type aliases
TokenList::copyTokens(tok1, start, usingEnd->previous());
tok1->deleteThis();
}
substitute = true; substitute = true;
} }
} else { } else {

View File

@ -71,6 +71,7 @@ private:
TEST_CASE(simplifyUsing26); // #11090 TEST_CASE(simplifyUsing26); // #11090
TEST_CASE(simplifyUsing27); TEST_CASE(simplifyUsing27);
TEST_CASE(simplifyUsing28); TEST_CASE(simplifyUsing28);
TEST_CASE(simplifyUsing29);
TEST_CASE(simplifyUsing8970); TEST_CASE(simplifyUsing8970);
TEST_CASE(simplifyUsing8971); TEST_CASE(simplifyUsing8971);
@ -684,6 +685,14 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void simplifyUsing29() { // #11981
const char code[] = "using T = int*;\n"
"void f(T = T()) {}\n";
const char expected[] = "void f ( int * = ( int * ) 0 ) { }";
ASSERT_EQUALS(expected, tok(code, cppcheck::Platform::Type::Native, /*debugwarnings*/ true));
ASSERT_EQUALS("", errout.str());
}
void simplifyUsing8970() { void simplifyUsing8970() {
const char code[] = "using V = std::vector<int>;\n" const char code[] = "using V = std::vector<int>;\n"
"struct A {\n" "struct A {\n"