From 16110b61574d9732a7f782238c31f1949aaad8dd Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Wed, 15 Dec 2021 12:34:18 -0600 Subject: [PATCH] Fix 10339: Lambda in leads to analysis fail (#3629) --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 99bbca07e..fb85983fd 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8734,7 +8734,7 @@ void Tokenizer::simplifyIfSwitchForInit() Token *semicolon = tok->tokAt(2); while (!Token::Match(semicolon, "[;)]")) { - if (semicolon->str() == "(") + if (Token::Match(semicolon, "(|{|[") && semicolon->link()) semicolon = semicolon->link(); semicolon = semicolon->next(); } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 7b3e84cba..a9c311dc6 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -442,6 +442,7 @@ private: TEST_CASE(simplifyIfSwitchForInit2); TEST_CASE(simplifyIfSwitchForInit3); TEST_CASE(simplifyIfSwitchForInit4); + TEST_CASE(simplifyIfSwitchForInit5); } #define tokenizeAndStringify(...) tokenizeAndStringify_(__FILE__, __LINE__, __VA_ARGS__) @@ -7141,6 +7142,13 @@ private: const char code[] = "void f() { for (a;b:c) {} }"; ASSERT_EQUALS("void f ( ) { { a ; for ( b : c ) { } } }", tokenizeAndStringify(code, settings)); } + + void simplifyIfSwitchForInit5() { + Settings settings; + settings.standards.cpp = Standards::CPP20; + const char code[] = "void f() { if ([] { ; }) {} }"; + ASSERT_EQUALS("void f ( ) { if ( [ ] { ; } ) { } }", tokenizeAndStringify(code, settings)); + } }; REGISTER_TEST(TestTokenizer)