Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #13104 FP CastIntegerToAddressAtReturn with function pointer and typedef #6802

Merged
merged 2 commits into from
Sep 16, 2024
Merged
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: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ namespace {
const bool isFunctionPointer = Token::Match(mNameToken, "%name% )");

// Special handling for T(...) when T is a pointer
if (Token::Match(tok, "%name% [({]") && !isFunctionPointer) {
if (Token::Match(tok, "%name% [({]") && !isFunctionPointer && !Token::simpleMatch(tok->linkAt(1), ") (")) {
bool pointerType = false;
for (const Token* type = mRangeType.first; type != mRangeType.second; type = type->next()) {
if (type->str() == "*" || type->str() == "&") {
Expand Down
11 changes: 11 additions & 0 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3388,6 +3388,17 @@ class TestSimplifyTypedef : public TestFixture {
const char code3[] = "typedef char* T;\n"
"T f() { return T(\"abc\"); }\n";
ASSERT_EQUALS("char * f ( ) { return ( char * ) ( \"abc\" ) ; }", tok(code3));

const char code4[] = "typedef struct _a *A;\n" // #13104
"typedef struct _b* B;\n"
"typedef A(get_t)(B);\n"
"extern get_t* get;\n"
"A f() {\n"
" return get(0);\n"
"}\n";
ASSERT_EQUALS("extern struct _a * ( * get ) ( struct _b * ) ; "
"struct _a * f ( ) { return get ( 0 ) ; }",
tok(code4));
}

void simplifyTypedef143() { // #11506
Expand Down
Loading