parent
f4df28d5ec
commit
212d2141d3
|
@ -471,6 +471,8 @@ static bool isDeadTemporary(bool cpp, const Token* tok, const Token* expr, const
|
|||
if (!precedes(nextAfterAstRightmostLeaf(tok->astTop()), nextAfterAstRightmostLeaf(expr->astTop())))
|
||||
return false;
|
||||
const Token* parent = tok->astParent();
|
||||
if (Token::simpleMatch(parent, "{") && Token::simpleMatch(parent->astParent(), ":"))
|
||||
parent = parent->astParent();
|
||||
// Is in a for loop
|
||||
if (astIsRHS(tok) && Token::simpleMatch(parent, ":") && Token::simpleMatch(parent->astParent(), "(") && Token::simpleMatch(parent->astParent()->previous(), "for (")) {
|
||||
const Token* braces = parent->astParent()->link()->next();
|
||||
|
|
|
@ -2144,6 +2144,15 @@ private:
|
|||
" (void)s.i;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:9]: (error) Using reference to dangling temporary.\n", errout.str());
|
||||
|
||||
check("std::string f() {\n" // #12173
|
||||
" std::string s;\n"
|
||||
" for (auto& c : { \"a\", \"b\", \"c\" }) {\n"
|
||||
" s += c;\n"
|
||||
" }\n"
|
||||
" return s;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void testglobalnamespace() {
|
||||
|
|
Loading…
Reference in New Issue