diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 87cd9b9dc..0e72ce2c6 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1598,7 +1598,7 @@ static Token * createAstAtToken(Token *tok, bool cpp) semicolon2->astOperand2(state3.op.top()); semicolon1->astOperand2(semicolon2); } else { - if (!cpp || !Token::simpleMatch(state2.op.top(), ":")) + if (!cpp || state2.op.empty() || !Token::simpleMatch(state2.op.top(), ":")) throw InternalError(tok, "syntax error", InternalError::SYNTAX); semicolon1->astOperand2(state2.op.top()); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 01be951e3..edd8a00a7 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -434,6 +434,7 @@ private: TEST_CASE(noCrash4); TEST_CASE(noCrash5); // #10603 TEST_CASE(noCrash6); // #10212 + TEST_CASE(noCrash7); // --check-config TEST_CASE(checkConfiguration); @@ -7357,6 +7358,12 @@ private: "struct c, true> {};\n")); } + void noCrash7() { + ASSERT_THROW(tokenizeAndStringify("void g() {\n"// TODO: don't throw + " for (using T = int; (T)false;) {}\n" // C++23 P2360R0: Extend init-statement to allow alias-declaration + "}\n"), InternalError); + } + void checkConfig(const char code[]) { errout.str("");