Fix #10839 internalAstError with function returning a function (#4514)

This commit is contained in:
chrchr-github 2022-09-29 21:56:26 +02:00 committed by GitHub
parent 0ab7116891
commit 260a757791
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -1720,6 +1720,10 @@ void TokenList::validateAst() const
tok = tok->link();
continue;
}
if (tok->isCast() && tok->astOperand1() && tok->link()) { // skip casts (not part of the AST)
tok = tok->link();
continue;
}
// Check binary operators
if (Token::Match(tok, "%or%|%oror%|%assign%|%comp%")) {

View File

@ -6227,6 +6227,26 @@ private:
ASSERT_EQUALS("adecltypeac::(,decltypead::(,",
testAst("template <typename a> void b(a &, decltype(a::c), decltype(a::d));"));
ASSERT_NO_THROW(tokenizeAndStringify("struct A;\n" // #10839
"struct B { A* hash; };\n"
"auto g(A* a) { return [=](void*) { return a; }; }\n"
"void f(void* p, B* b) {\n"
" b->hash = (g(b->hash))(p);\n"
"}\n"));
ASSERT_NO_THROW(tokenizeAndStringify("struct A;\n"
"struct B { A* hash; };\n"
"A* h(void* p);\n"
"typedef A* (*X)(void*);\n"
"X g(A*) { return h; }\n"
"void f(void* p, B * b) {\n"
"b->hash = (g(b->hash))(p);\n"
"}\n"));
ASSERT_NO_THROW(tokenizeAndStringify("struct A;\n"
"struct B { A* hash; };\n"
"void f(void* p, B* b) {\n"
" b->hash = (decltype(b->hash))(p);\n"
"}\n"));
// #10334: Do not hang!
tokenizeAndStringify("void foo(const std::vector<std::string>& locations = {\"\"}) {\n"
" for (int i = 0; i <= 123; ++i)\n"