From d24074f7b1dcf2cc2d10a9a7e0f0343a56b6572f Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 9 Nov 2023 10:11:34 +0100 Subject: [PATCH] Fix #12166 debug: varid0 with reference typedef (#5643) Why do we even split any declarations in the first place? --- lib/tokenize.cpp | 3 ++- test/testsimplifytypedef.cpp | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index cb8b153eb..f8b050f99 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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(); } diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 7d4eb221b..1e5570e6f 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -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"