From db09abdb21b5893a387ed017a1edbb51444d6b0d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 23 Mar 2026 13:08:57 +0100 Subject: [PATCH] =?UTF-8?q?Revert=20"Fix=20=20#14613=20Crash=20in=20compil?= =?UTF-8?q?ePrecedence2()=20(function=20called=20requires)=20=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 74e6823ca873473c743f2c43d1122622984b4952. --- lib/tokenlist.cpp | 8 +++----- test/testtokenize.cpp | 6 ------ 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 55ca98c628c..7f7ca25aa5c 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1058,12 +1058,10 @@ static void compilePrecedence2(Token *&tok, AST_state& state) else compileUnaryOp(tok, state, compileExpression); tok = tok2->link()->next(); - } else if ((Token::simpleMatch(tok->tokAt(-1), "requires {") && tok->tokAt(-1)->isKeyword()) - || (Token::simpleMatch(tok->tokAt(-1), ")") + } else if (Token::simpleMatch(tok->previous(), "requires {") + || (Token::simpleMatch(tok->previous(), ")") && tok->linkAt(-1) - && Token::simpleMatch(tok->linkAt(-1)->tokAt(-1), "requires (") && tok->linkAt(-1)->tokAt(-1)->isKeyword())) { - if (!tok->link()) - throw InternalError(tok, "Syntax error, token has no link.", InternalError::AST); + && Token::simpleMatch(tok->linkAt(-1)->previous(), "requires ("))) { tok->astOperand1(state.op.top()); state.op.pop(); state.op.push(tok); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 7a33f757737..f78899820b2 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -8332,12 +8332,6 @@ class TestTokenizer : public TestFixture { void cppKeywordInCSource() { ASSERT_NO_THROW(tokenizeAndStringify("int throw() {}", dinit(TokenizeOptions, $.cpp = false))); - - const char code[] = "void requires(const char*);\n" // #14613 - "void f() { requires(\"abc\"); }\n"; - ASSERT_NO_THROW(tokenizeAndStringify(code, dinit(TokenizeOptions, $.cpp = false))); - ASSERT_NO_THROW(tokenizeAndStringify(code, dinit(TokenizeOptions, $.cpp = true, $.cppstd = Standards::CPP17))); - ASSERT_THROW_INTERNAL(tokenizeAndStringify(code, dinit(TokenizeOptions, $.cpp = true, $.cppstd = Standards::CPP20)), AST); } void cppcast() {