Fix issue 9889: False positive: Using reference to dangling temporary with function object
This commit is contained in:
parent
2b12ef653d
commit
71bc79ac28
|
@ -247,12 +247,12 @@ bool isTemporary(bool cpp, const Token* tok, const Library* library, bool unknow
|
|||
return false;
|
||||
if (Token::Match(tok, "&|<<|>>") && isLikelyStream(cpp, tok->astOperand1()))
|
||||
return false;
|
||||
if (Token::Match(tok->previous(), ">|%name% (")) {
|
||||
if (Token::simpleMatch(tok, "(") && tok->astOperand1() && (tok->astOperand2() || Token::simpleMatch(tok->next(), ")"))) {
|
||||
if (tok->valueType()) {
|
||||
return tok->valueType()->reference == Reference::None;
|
||||
}
|
||||
const Token* ftok = nullptr;
|
||||
if (tok->previous()->link())
|
||||
if (Token::simpleMatch(tok->previous(), ">") && tok->previous()->link())
|
||||
ftok = tok->previous()->link()->previous();
|
||||
else
|
||||
ftok = tok->previous();
|
||||
|
|
|
@ -1343,6 +1343,13 @@ private:
|
|||
" return a()();\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #9889
|
||||
check("int f(std::vector<std::function<int&()>>& v, int i) {\n"
|
||||
" auto& j = v[i]();\n"
|
||||
" return j;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void returnReferenceFunction() {
|
||||
|
|
Loading…
Reference in New Issue