Don't crash on C++23 code (#4771)

This commit is contained in:
chrchr-github 2023-02-07 22:36:42 +01:00 committed by GitHub
parent 55292d476a
commit 1fcea5fb03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -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());

View File

@ -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<a<e, d...>, 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("");