#5844 False positive: returnReference fp for inner lambda function
This commit is contained in:
parent
80f445bf6f
commit
d492500f34
|
@ -423,6 +423,33 @@ static bool astHasAutoResult(const Token *tok)
|
|||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Skip over a lambda expression
|
||||
* \return next token - or next token beyond lambda
|
||||
* \todo handle explicit return type
|
||||
*/
|
||||
static const Token* skipLambda(const Token* first)
|
||||
{
|
||||
if (!first)
|
||||
return nullptr;
|
||||
if (first->str() != "[")
|
||||
return first;
|
||||
const Token* tok = first->link()->next();
|
||||
if (!tok)
|
||||
return nullptr;
|
||||
if (tok->str() == "(") {
|
||||
tok = tok->link()->next();
|
||||
}
|
||||
if (tok->str() == "constexpr")
|
||||
tok = tok->next();
|
||||
if (tok->str() == "mutable")
|
||||
tok = tok->next();
|
||||
if (tok->str() == "{") {
|
||||
tok = tok->link()->next();
|
||||
}
|
||||
return tok;
|
||||
}
|
||||
|
||||
void CheckAutoVariables::returnReference()
|
||||
{
|
||||
if (_tokenizer->isC())
|
||||
|
@ -447,10 +474,9 @@ void CheckAutoVariables::returnReference()
|
|||
}
|
||||
|
||||
// Skip over lambdas
|
||||
if (tok2->str() == "[" && tok2->link()->strAt(1) == "(" && tok2->link()->linkAt(1)->strAt(1) == "{")
|
||||
tok2 = tok2->link()->linkAt(1)->linkAt(1);
|
||||
tok2 = skipLambda(tok2);
|
||||
|
||||
if (tok2->str() != "return")
|
||||
if (!tok2 || tok2->str() != "return")
|
||||
continue;
|
||||
|
||||
// return..
|
||||
|
|
|
@ -1023,6 +1023,16 @@ private:
|
|||
" });\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #5844
|
||||
check("map<string,string> const &getVariableTable() {\n"
|
||||
"static map<string,string> const s_var = []{\n"
|
||||
" map<string,string> var;\n"
|
||||
" return var;\n"
|
||||
" }();\n"
|
||||
"return s_var;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void returnReferenceInnerScope() {
|
||||
|
|
Loading…
Reference in New Issue