Skip to content

Commit 408daf9

Browse files
committed
Fix #14967 internalAstError with function pointer in if
1 parent baf5eaa commit 408daf9

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/tokenlist.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ static Token* skipDecl(Token* tok, std::vector<Token*>* inner = nullptr)
461461
return Token::Match(tok, "%name%| ,|)");
462462
};
463463

464-
if (!Token::Match(tok->previous(), "( %name%"))
464+
if (tok->varId() || !Token::Match(tok->previous(), "( %name%"))
465465
return tok;
466466
Token *vartok = tok;
467467
while (Token::Match(vartok, "%name%|*|&|&&|::|<")) {

test/testtokenize.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ class TestTokenizer : public TestFixture {
446446
TEST_CASE(astfuncdecl);
447447
TEST_CASE(astarrayinit);
448448
TEST_CASE(astbracedinit);
449+
TEST_CASE(astif);
449450

450451
TEST_CASE(startOfExecutableScope);
451452

@@ -7643,6 +7644,14 @@ class TestTokenizer : public TestFixture {
76437644
ASSERT_EQUALS("anullptr{", testAst("int *a { nullptr };", AstStyle::Simple, ListSimplification::Full));
76447645
}
76457646

7647+
void astif() {
7648+
ASSERT_EQUALS( // #14967
7649+
"ifxx(&&(",
7650+
testAst("void f(int (*x)()) {\n"
7651+
" if (x && x()) {}\n"
7652+
"}\n", AstStyle::Simple, ListSimplification::Full));
7653+
}
7654+
76467655
#define isStartOfExecutableScope(offset, code) isStartOfExecutableScope_(offset, code, __FILE__, __LINE__)
76477656
template<size_t size>
76487657
bool isStartOfExecutableScope_(int offset, const char (&code)[size], const char* file, int line) {

0 commit comments

Comments
 (0)