Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ bool isTemporary(const Token* tok, const Library* library, bool unknown)
return isTemporary(tok->astOperand2(), library);
if (tok->isCast() || (tok->isCpp() && isCPPCast(tok)))
return isTemporary(tok->astOperand2(), library);
if (findLambdaEndToken(tok) != nullptr)
return true;
if (Token::Match(tok, ".|[|++|--|%name%|%assign%"))
return false;
if (tok->isUnaryOp("*"))
Expand Down
15 changes: 15 additions & 0 deletions test/testautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4209,6 +4209,21 @@ class TestAutoVariables : public TestFixture {
" if (!p) {}\n"
"}\n");
ASSERT_EQUALS("", errout_str());

// #13760
check("template<class T>\n"
"auto f(T&& x) {\n"
" return [&] {\n"
" return x();\n"
" };\n"
"}\n"
"auto g() {\n"
" auto y = f([](auto x) { return 1; });\n"
" return y();\n"
"}\n");
ASSERT_EQUALS(
"[test.cpp:3:12] -> [test.cpp:2:13] -> [test.cpp:4:16] -> [test.cpp:8:16] -> [test.cpp:8:16] -> [test.cpp:9:12]: (error) Using object that is a temporary. [danglingTemporaryLifetime]\n",
errout_str());
}

void danglingLifetimeBorrowedMembers()
Expand Down
Loading