Fix #12166 debug: varid0 with reference typedef (#5643)

Why do we even split any declarations in the first place?
This commit is contained in:
chrchr-github 2023-11-09 10:11:34 +01:00 committed by GitHub
parent 780b742568
commit d24074f7b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -891,7 +891,8 @@ namespace {
tok->deleteThis();
// Unsplit variable declarations
if (Token::Match(tok4->previous(), "] ; %name% = {") && tok4->isSplittedVarDeclEq()) {
if (tok4 && tok4->isSplittedVarDeclEq() &&
((tok4->isCpp() && Token::Match(tok4->tokAt(-2), "& %name% ;")) || Token::Match(tok4->previous(), "] ; %name% = {"))) {
tok4->deleteNext();
tok4->deleteThis();
}

View File

@ -211,6 +211,7 @@ private:
TEST_CASE(simplifyTypedef145); // #9353
TEST_CASE(simplifyTypedef146);
TEST_CASE(simplifyTypedef147);
TEST_CASE(simplifyTypedef148);
TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -3435,6 +3436,13 @@ private:
tok(code));
}
void simplifyTypedef148() {
const char* code{};
code = "typedef int& R;\n" // #12166
"R r = i;\n";
ASSERT_EQUALS("int & r = i ;", tok(code));
}
void simplifyTypedefFunction1() {
{
const char code[] = "typedef void (*my_func)();\n"