Skip to content

Commit d8d2ece

Browse files
chrchr-githubweb-flow
authored andcommitted
Revert "Fix #14613 Crash in compilePrecedence2() (function called requires)" (broken build) (cppcheck-opensource#8370)
Reverts cppcheck-opensource#8361
1 parent 1428a46 commit d8d2ece

2 files changed

Lines changed: 3 additions & 11 deletions

File tree

lib/tokenlist.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,12 +1058,10 @@ static void compilePrecedence2(Token *&tok, AST_state& state)
10581058
else
10591059
compileUnaryOp(tok, state, compileExpression);
10601060
tok = tok2->link()->next();
1061-
} else if ((Token::simpleMatch(tok->tokAt(-1), "requires {") && tok->tokAt(-1)->isKeyword())
1062-
|| (Token::simpleMatch(tok->tokAt(-1), ")")
1061+
} else if (Token::simpleMatch(tok->previous(), "requires {")
1062+
|| (Token::simpleMatch(tok->previous(), ")")
10631063
&& tok->linkAt(-1)
1064-
&& Token::simpleMatch(tok->linkAt(-1)->tokAt(-1), "requires (") && tok->linkAt(-1)->tokAt(-1)->isKeyword())) {
1065-
if (!tok->link())
1066-
throw InternalError(tok, "Syntax error, token has no link.", InternalError::AST);
1064+
&& Token::simpleMatch(tok->linkAt(-1)->previous(), "requires ("))) {
10671065
tok->astOperand1(state.op.top());
10681066
state.op.pop();
10691067
state.op.push(tok);

test/testtokenize.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8332,12 +8332,6 @@ class TestTokenizer : public TestFixture {
83328332

83338333
void cppKeywordInCSource() {
83348334
ASSERT_NO_THROW(tokenizeAndStringify("int throw() {}", dinit(TokenizeOptions, $.cpp = false)));
8335-
8336-
const char code[] = "void requires(const char*);\n" // #14613
8337-
"void f() { requires(\"abc\"); }\n";
8338-
ASSERT_NO_THROW(tokenizeAndStringify(code, dinit(TokenizeOptions, $.cpp = false)));
8339-
ASSERT_NO_THROW(tokenizeAndStringify(code, dinit(TokenizeOptions, $.cpp = true, $.cppstd = Standards::CPP17)));
8340-
ASSERT_THROW_INTERNAL(tokenizeAndStringify(code, dinit(TokenizeOptions, $.cpp = true, $.cppstd = Standards::CPP20)), AST);
83418335
}
83428336

83438337
void cppcast() {

0 commit comments

Comments
 (0)