Skip to content

Commit 3cfa70d

Browse files
Fix #14256 syntaxError for C++23 lambda without parameter clause (#7953)
1 parent 2af570d commit 3cfa70d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8920,7 +8920,7 @@ void Tokenizer::findGarbageCode() const
89208920
if (Token::Match(tok, "!|~ %comp%") &&
89218921
!(cpp && tok->strAt(1) == ">" && Token::simpleMatch(tok->tokAt(-1), "operator")))
89228922
syntaxError(tok);
8923-
if (Token::Match(tok, "] %name%") && (!cpp || !(tok->tokAt(-1) && Token::simpleMatch(tok->tokAt(-2), "delete [")))) {
8923+
if (Token::Match(tok, "] %name%") && (!cpp || !(tok->tokAt(1)->isKeyword() || (tok->tokAt(-1) && Token::simpleMatch(tok->tokAt(-2), "delete ["))))) {
89248924
if (tok->next()->isUpperCaseName())
89258925
unknownMacroError(tok->next());
89268926
else

test/testtokenize.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7994,6 +7994,12 @@ class TestTokenizer : public TestFixture {
79947994
"int main() { \n"
79957995
" takesFunc([func = [](S s) { return s.c; }] {});\n"
79967996
"}\n"));
7997+
7998+
ASSERT_NO_THROW(tokenizeAndStringify("void f() {\n" // #14256
7999+
" int i = 0;\n"
8000+
" auto x = [i] mutable {};\n"
8001+
"}\n"));
8002+
79978003
ignore_errout();
79988004
}
79998005
void checkIfCppCast() {

0 commit comments

Comments
 (0)