Fix #11370 FP constStatement with lambda (#4570)

* Update tokenlist.cpp

* Update testincompletestatement.cpp

* Fix #11370 FP constStatement with lambda

* Format
This commit is contained in:
chrchr-github 2022-11-01 11:50:08 +01:00 committed by GitHub
parent d717e62ec3
commit ccf2176664
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View File

@ -493,6 +493,17 @@ static Token * createAstAtToken(Token *tok, bool cpp);
static Token* skipDecl(Token* tok, std::vector<Token*>* inner = nullptr)
{
auto isDecltypeFuncParam = [](const Token* tok) -> bool {
if (!Token::simpleMatch(tok, ")"))
return false;
tok = tok->next();
while (Token::Match(tok, "*|&|&&|const"))
tok = tok->next();
if (Token::simpleMatch(tok, "("))
tok = tok->link()->next();
return Token::Match(tok, "%name%| ,|)");
};
if (!Token::Match(tok->previous(), "( %name%"))
return tok;
Token *vartok = tok;
@ -504,7 +515,7 @@ static Token* skipDecl(Token* tok, std::vector<Token*>* inner = nullptr)
return tok;
} else if (Token::Match(vartok, "%var% [:=(]")) {
return vartok;
} else if (Token::Match(vartok, "decltype|typeof (") && !Token::Match(tok->linkAt(1), ") [,)]")) {
} else if (Token::Match(vartok, "decltype|typeof (") && !isDecltypeFuncParam(tok->linkAt(1))) {
if (inner)
inner->push_back(vartok->tokAt(2));
return vartok->linkAt(1)->next();

View File

@ -709,6 +709,12 @@ private:
" (*s).i;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant code: Found unused member access.\n", errout.str());
check("int a[2];\n" // #11370
"void f() {\n"
" auto g = [](decltype(a[0]) i) {};\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void vardecl() {

View File

@ -6243,6 +6243,10 @@ private:
ASSERT_EQUALS("decltypexy+(yx+{", testAst("decltype(x+y){y+x};"));
ASSERT_EQUALS("adecltypeac::(,decltypead::(,",
testAst("template <typename a> void b(a &, decltype(a::c), decltype(a::d));"));
ASSERT_EQUALS("g{([= decltypea0[(",
testAst("auto g = [](decltype(a[0]) i) {};"));
ASSERT_EQUALS("g{([= decltypea0[(i&",
testAst("auto g = [](decltype(a[0])& i) {};"));
ASSERT_NO_THROW(tokenizeAndStringify("struct A;\n" // #10839
"struct B { A* hash; };\n"