diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0ad9ddef1d6..5382322d160 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1034,6 +1034,8 @@ namespace { to = to->next(); to->isSimplifiedTypedef(true); to->isExternC(from->isExternC()); + if (from->isExpandedMacro()) + to->setMacroName(from->getMacroName()); } return to; } diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 26b24d649c8..20d0bc1400b 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -267,6 +267,8 @@ Token *TokenList::copyTokens(Token *dest, const Token *first, const Token *last, tok2->flags(tok->flags()); tok2->varId(tok->varId()); tok2->setTokenDebug(tok->getTokenDebug()); + if (tok->isExpandedMacro()) + tok2->setMacroName(tok->getMacroName()); // Check for links and fix them up if (Token::Match(tok2, "(|[|{")) diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 8ea0766c977..ef6c9a3a6f9 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -254,6 +254,7 @@ class TestSimplifyTypedef : public TestFixture { TEST_CASE(simplifyTypedefShadow); // #4445 - shadow variable TEST_CASE(simplifyTypedefMacro); + TEST_CASE(simplifyTypedefMacroName); TEST_CASE(simplifyTypedefOriginalName1); TEST_CASE(simplifyTypedefOriginalName2); @@ -4547,6 +4548,16 @@ class TestSimplifyTypedef : public TestFixture { simplifyTypedefP(code)); } + void simplifyTypedefMacroName() { + const char code[] = "#define A int\n" + "typedef void (*F)(A x);\n" + "void f(F g);\n"; + SimpleTokenizer2 tokenizer(settings0, *this, code, "test.c"); + tokenizer.createLinks(); + tokenizer.simplifyTypedef(); + ASSERT_EQUALS("void f ( void ( * g ) ( $int x ) ) ;", tokenizer.tokens()->stringifyList(false, true, false, false, false)); + } + void simplifyTypedefOriginalName1() { const char code[] = "typedef unsigned char uint8_t;\n" "typedef float (*rFunctionPointer_fp)(uint8_t, uint8_t);\n"