Fix 10339: Lambda in leads to analysis fail (#3629)

This commit is contained in:
Paul Fultz II 2021-12-15 12:34:18 -06:00 committed by GitHub
parent 5f73af0d0e
commit 16110b6157
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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();
}

View File

@ -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)