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
3 changes: 1 addition & 2 deletions addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,8 +803,7 @@ def get_function_pointer_type(tok):
ret += '('
tok = tok.next.next
while tok and (tok.str not in '()'):
if tok.varId is None:
ret += ' ' + tok.str
ret += ' ' + tok.str
tok = tok.next
if (tok is None) or tok.str != ')':
return None
Expand Down
7 changes: 6 additions & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,12 @@ namespace {
}

bool Tokenizer::isFunctionPointer(const Token* tok) {
return Token::Match(tok, "%name% ) (");
if (!Token::Match(tok, "%name%"))
return false;
tok = tok->next();
while (Token::Match(tok, "["))
tok = tok->link()->next();
return Token::simpleMatch(tok, ") (");
}

static bool matchCurrentType(const Token* tok, std::map<int, std::string>& types)
Expand Down
10 changes: 8 additions & 2 deletions test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ class TestVarID : public TestFixture {
ASSERT_EQUALS(expected2, tokenize(code2));

const char code3[] = "extern void (*arr[10])(uint32_t some);\n";
const char expected3[] = "1: extern void ( * arr@1 [ 10 ] ) ( uint32_t some@2 ) ;\n";
const char expected3[] = "1: extern void ( * arr@1 [ 10 ] ) ( uint32_t ) ;\n";
ASSERT_EQUALS(expected3, tokenize(code3));

const char code4[] = "_Static_assert(sizeof((struct S){0}.i) == 4);\n"; // #12729
Expand Down Expand Up @@ -3545,9 +3545,15 @@ class TestVarID : public TestFixture {
"}\n";
ASSERT_EQUALS("1: void f ( ) {\n"
"2: int * p@1 ;\n"
"3: void ( * a@2 [ 1 ] ) ( int * p ) = { 0 } ;\n"
"3: void ( * a@2 [ 1 ] ) ( int * ) = { 0 } ;\n"
"4: }\n",
tokenize(code4));

const char code5[] = "int *p;\n"
"void (*a[1])(int* p) = { 0 } ;\n";
ASSERT_EQUALS("1: int * p@1 ;\n"
"2: void ( * a@2 [ 1 ] ) ( int * ) = { 0 } ;\n"
, tokenize(code5));
}

void varid_alignas() {
Expand Down
Loading