Skip to content

Commit 1fcea5f

Browse files
Don't crash on C++23 code (#4771)
1 parent 55292d4 commit 1fcea5f

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

lib/tokenlist.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ static Token * createAstAtToken(Token *tok, bool cpp)
15981598
semicolon2->astOperand2(state3.op.top());
15991599
semicolon1->astOperand2(semicolon2);
16001600
} else {
1601-
if (!cpp || !Token::simpleMatch(state2.op.top(), ":"))
1601+
if (!cpp || state2.op.empty() || !Token::simpleMatch(state2.op.top(), ":"))
16021602
throw InternalError(tok, "syntax error", InternalError::SYNTAX);
16031603

16041604
semicolon1->astOperand2(state2.op.top());

test/testtokenize.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ class TestTokenizer : public TestFixture {
434434
TEST_CASE(noCrash4);
435435
TEST_CASE(noCrash5); // #10603
436436
TEST_CASE(noCrash6); // #10212
437+
TEST_CASE(noCrash7);
437438

438439
// --check-config
439440
TEST_CASE(checkConfiguration);
@@ -7357,6 +7358,12 @@ class TestTokenizer : public TestFixture {
73577358
"struct c<a<e, d...>, true> {};\n"));
73587359
}
73597360

7361+
void noCrash7() {
7362+
ASSERT_THROW(tokenizeAndStringify("void g() {\n"// TODO: don't throw
7363+
" for (using T = int; (T)false;) {}\n" // C++23 P2360R0: Extend init-statement to allow alias-declaration
7364+
"}\n"), InternalError);
7365+
}
7366+
73607367
void checkConfig(const char code[]) {
73617368
errout.str("");
73627369

0 commit comments

Comments
 (0)