diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index b632085ee..f34dd8c5d 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -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%")) { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 20dfb5aea..273088529 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6227,6 +6227,26 @@ private: ASSERT_EQUALS("adecltypeac::(,decltypead::(,", testAst("template 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& locations = {\"\"}) {\n" " for (int i = 0; i <= 123; ++i)\n"