Skip to content

Commit f4f4ce8

Browse files
Fix #13104 FP CastIntegerToAddressAtReturn with function pointer and typedef (#6802)
1 parent 08b5016 commit f4f4ce8

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ namespace {
755755
const bool isFunctionPointer = Token::Match(mNameToken, "%name% )");
756756

757757
// Special handling for T(...) when T is a pointer
758-
if (Token::Match(tok, "%name% [({]") && !isFunctionPointer) {
758+
if (Token::Match(tok, "%name% [({]") && !isFunctionPointer && !Token::simpleMatch(tok->linkAt(1), ") (")) {
759759
bool pointerType = false;
760760
for (const Token* type = mRangeType.first; type != mRangeType.second; type = type->next()) {
761761
if (type->str() == "*" || type->str() == "&") {

test/testsimplifytypedef.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3388,6 +3388,17 @@ class TestSimplifyTypedef : public TestFixture {
33883388
const char code3[] = "typedef char* T;\n"
33893389
"T f() { return T(\"abc\"); }\n";
33903390
ASSERT_EQUALS("char * f ( ) { return ( char * ) ( \"abc\" ) ; }", tok(code3));
3391+
3392+
const char code4[] = "typedef struct _a *A;\n" // #13104
3393+
"typedef struct _b* B;\n"
3394+
"typedef A(get_t)(B);\n"
3395+
"extern get_t* get;\n"
3396+
"A f() {\n"
3397+
" return get(0);\n"
3398+
"}\n";
3399+
ASSERT_EQUALS("extern struct _a * ( * get ) ( struct _b * ) ; "
3400+
"struct _a * f ( ) { return get ( 0 ) ; }",
3401+
tok(code4));
33913402
}
33923403

33933404
void simplifyTypedef143() { // #11506

0 commit comments

Comments
 (0)