Fix #10917 FP constStatement with immediately evaluated lambda (#3956)

This commit is contained in:
chrchr-github 2022-03-29 06:10:57 +02:00 committed by GitHub
parent 81bcbfa7fe
commit 86ff360946
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -8870,9 +8870,11 @@ bool Tokenizer::simplifyRedundantParentheses()
if (tok->str() != "(")
continue;
if (isCPP() && Token::simpleMatch(tok->previous(), "} (") &&
Token::Match(tok->previous()->link()->previous(), "%name%|> {"))
continue;
if (isCPP() && Token::simpleMatch(tok->previous(), "} (")) {
const Token* plp = tok->previous()->link()->previous();
if (Token::Match(plp, "%name%|>|] {") || (Token::simpleMatch(plp, ")") && Token::simpleMatch(plp->link()->previous(), "]")))
continue;
}
if (Token::simpleMatch(tok, "( {"))
continue;

View File

@ -579,6 +579,12 @@ private:
" E e = (E)!s->i;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("struct S { int i; };\n" // #10917
"bool f(S s) {\n"
" return [](int i) { return i > 0; }(s.i);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void vardecl() {