Skip to content
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
4 changes: 2 additions & 2 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,9 +752,10 @@ namespace {
return;

mUsed = true;
const bool isFunctionPointer = Token::Match(mNameToken, "%name% )");

// Special handling for T(...) when T is a pointer
if (Token::Match(tok, "%name% [({]") && !Token::simpleMatch(tok->linkAt(1), ") (")) {
if (Token::Match(tok, "%name% [({]") && !isFunctionPointer) {
bool pointerType = false;
for (const Token* type = mRangeType.first; type != mRangeType.second; type = type->next()) {
if (type->str() == "*" || type->str() == "&") {
Expand Down Expand Up @@ -791,7 +792,6 @@ namespace {
}

// Special handling of function pointer cast
const bool isFunctionPointer = Token::Match(mNameToken, "%name% )");
if (isFunctionPointer && isCast(tok->previous())) {
tok->insertToken("*");
Token* const tok_1 = insertTokens(tok, std::pair<Token*, Token*>(mRangeType.first, mNameToken->linkAt(1)));
Expand Down
22 changes: 22 additions & 0 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class TestSimplifyTypedef : public TestFixture {
TEST_CASE(simplifyTypedefFunction8);
TEST_CASE(simplifyTypedefFunction9);
TEST_CASE(simplifyTypedefFunction10); // #5191
TEST_CASE(simplifyTypedefFunction11);

TEST_CASE(simplifyTypedefStruct); // #12081 - volatile struct

Expand Down Expand Up @@ -4315,6 +4316,27 @@ class TestSimplifyTypedef : public TestFixture {
tok(code,false));
}

void simplifyTypedefFunction11() {
const char code[] = "typedef void (*func_t) (int);\n"
"void g(int);\n"
"void f(void* p) {\n"
" if (g != func_t(p)) {}\n"
" if (g != (func_t)p) {}\n"
"}\n";
TODO_ASSERT_EQUALS("void g ( int ) ; "
"void f ( void * p ) { "
"if ( g != ( void ( * ) ( int ) ) ( p ) ) { } "
"if ( g != ( void ( * ) ( int ) ) p ) { } "
"}",
"void g ( int ) ; "
"void f ( void * p ) { "
"if ( g != void * ( p ) ) { } "
"if ( g != ( void * ) p ) { } "
"}",
tok(code,false));
ignore_errout(); // we are not interested in the output
}

void simplifyTypedefStruct() {
const char code1[] = "typedef struct S { int x; } xyz;\n"
"xyz var;";
Expand Down