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())))
|
if (!precedes(nextAfterAstRightmostLeaf(tok->astTop()), nextAfterAstRightmostLeaf(expr->astTop())))
|
||||||
return false;
|
return false;
|
||||||
const Token* parent = tok->astParent();
|
const Token* parent = tok->astParent();
|
||||||
|
if (Token::simpleMatch(parent, "{") && Token::simpleMatch(parent->astParent(), ":"))
|
||||||
|
parent = parent->astParent();
|
||||||
// Is in a for loop
|
// Is in a for loop
|
||||||
if (astIsRHS(tok) && Token::simpleMatch(parent, ":") && Token::simpleMatch(parent->astParent(), "(") && Token::simpleMatch(parent->astParent()->previous(), "for (")) {
|
if (astIsRHS(tok) && Token::simpleMatch(parent, ":") && Token::simpleMatch(parent->astParent(), "(") && Token::simpleMatch(parent->astParent()->previous(), "for (")) {
|
||||||
const Token* braces = parent->astParent()->link()->next();
|
const Token* braces = parent->astParent()->link()->next();
|
||||||
|
|
|
@ -2144,6 +2144,15 @@ private:
|
||||||
" (void)s.i;\n"
|
" (void)s.i;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:9]: (error) Using reference to dangling temporary.\n", errout.str());
|
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() {
|
void testglobalnamespace() {
|
||||||
|
|
Loading…
Reference in New Issue