Skip to content

Commit ab753cd

Browse files
Fix #14967 internalAstError with function pointer in if (#8782)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent fd79f15 commit ab753cd

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
@@ -463,7 +463,7 @@ static Token* skipDecl(Token* tok, std::vector<Token*>* inner = nullptr)
463463
return Token::Match(tok, "%name%| ,|)");
464464
};
465465

466-
if (!Token::Match(tok->previous(), "( %name%"))
466+
if (tok->varId() || !Token::Match(tok->previous(), "( %name%"))
467467
return tok;
468468
Token *vartok = tok;
469469
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

@@ -7728,6 +7729,14 @@ class TestTokenizer : public TestFixture {
77287729
ASSERT_EQUALS("anullptr{", testAst("int *a { nullptr };\n", AstStyle::Simple, ListSimplification::Full));
77297730
}
77307731

7732+
void astif() {
7733+
ASSERT_EQUALS( // #14967
7734+
"ifxx(&&(",
7735+
testAst("void f(int (*x)()) {\n"
7736+
" if (x && x()) {}\n"
7737+
"}\n", AstStyle::Simple, ListSimplification::Full));
7738+
}
7739+
77317740
#define isStartOfExecutableScope(offset, code) isStartOfExecutableScope_(offset, code, __FILE__, __LINE__)
77327741
template<size_t size>
77337742
bool isStartOfExecutableScope_(int offset, const char (&code)[size], const char* file, int line) {

0 commit comments

Comments
 (0)