Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,8 @@ namespace {
to = to->next();
to->isSimplifiedTypedef(true);
to->isExternC(from->isExternC());
if (from->isExpandedMacro())
to->setMacroName(from->getMacroName());
}
return to;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review

No test covers this change. If I revert it, TestSimplifyTypedef (including the new simplifyTypedefMacroName) and the rest of the testrunner still pass, because the new test only goes through TypedefSimplifier::insertTokens. copyTokens is used by simplifyUsing, simplifyTypedefCpp and the template simplifier, and the effect is visible there. For example, with #define A int / using F = void (*)(A x); / void f(F g);, the PR gives ( $int ) where base gives ( int ). Please add a test for this path, for example in TestSimplifyUsing.


// Check for links and fix them up
if (Token::Match(tok2, "(|[|{"))
Expand Down
11 changes: 11 additions & 0 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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"
Expand Down
Loading