Fix issue 9608: False Positive: returnDanglingLifetime with braced-init-list (#2583)
This commit is contained in:
parent
02ae71917a
commit
71deaaeb18
|
@ -3384,10 +3384,18 @@ static void valueFlowLifetimeConstructor(Token* tok, TokenList* tokenlist, Error
|
|||
valueFlowLifetimeConstructor(tok, Token::typeOf(parent->previous()), tokenlist, errorLogger, settings);
|
||||
} else if (Token::simpleMatch(tok, "{") && hasInitList(parent)) {
|
||||
std::vector<const Token *> args = getArguments(tok);
|
||||
// Assume range constructor if passed a pair of iterators
|
||||
if (astIsContainer(parent) && args.size() == 2 && astIsIterator(args[0]) && astIsIterator(args[1])) {
|
||||
for (const Token *argtok : args) {
|
||||
LifetimeStore ls{argtok, "Passed to initializer list.", ValueFlow::Value::LifetimeKind::Object};
|
||||
ls.byDerefCopy(tok, tokenlist, errorLogger, settings);
|
||||
}
|
||||
} else {
|
||||
for (const Token *argtok : args) {
|
||||
LifetimeStore ls{argtok, "Passed to initializer list.", ValueFlow::Value::LifetimeKind::Object};
|
||||
ls.byVal(tok, tokenlist, errorLogger, settings);
|
||||
}
|
||||
}
|
||||
} else if (const Type* t = Token::typeOf(tok->previous())) {
|
||||
valueFlowLifetimeConstructor(tok, t, tokenlist, errorLogger, settings);
|
||||
}
|
||||
|
|
|
@ -2476,6 +2476,14 @@ private:
|
|||
" return {&x, &x};\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("std::vector<std::string> f() {\n"
|
||||
" std::set<std::string> x;\n"
|
||||
" x.insert(\"1\");\n"
|
||||
" x.insert(\"2\");\n"
|
||||
" return { x.begin(), x.end() };\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void danglingLifetimeImplicitConversion() {
|
||||
|
|
Loading…
Reference in New Issue