From 8b1ed9cbe168baa319cb37c3982462db4a8e417f Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sat, 22 Jan 2022 00:22:57 -0600 Subject: [PATCH] Another fix for 10739: internalAstError with decltype (#3738) * Another fix for 10739: internalAstError with decltype * Format --- lib/tokenlist.cpp | 6 ++++++ test/testtokenize.cpp | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 4cee3f838..fa5dccbfa 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -784,7 +784,13 @@ static void compileTerm(Token *&tok, AST_state& state) tok = tok->tokAt(2); } } else if (!state.cpp || !Token::Match(tok, "new|delete %name%|*|&|::|(|[")) { + Token* tok2 = tok; tok = skipDecl(tok); + if (Token::simpleMatch(tok2, "decltype (")) { + Token* tok3 = tok2->next(); + AST_state state1(state.cpp); + compileExpression(tok3, state1); + } bool repeat = true; while (repeat) { repeat = false; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 90638b15f..ec7e4741c 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6885,6 +6885,15 @@ private: ASSERT_NO_THROW(tokenizeAndStringify("void a() {\n" " [b = [] { ; }] {};\n" "}\n")); + + // #10739 + ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n" + " std::vector b;\n" + "};\n" + "void c() {\n" + " a bar;\n" + " (decltype(bar.b)::value_type){};\n" + "}\n")); } void checkIfCppCast() { ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n"