From 86ff360946a86a2a8cab6d5cdc6712927ffdadfd Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 29 Mar 2022 06:10:57 +0200 Subject: [PATCH] Fix #10917 FP constStatement with immediately evaluated lambda (#3956) --- lib/tokenize.cpp | 8 +++++--- test/testincompletestatement.cpp | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 232e57c6e..7976e7f0c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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; diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 3bb3526da..2fb53cc1b 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -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() {