parent
704b862a2d
commit
a57fc9ace6
|
@ -3470,7 +3470,7 @@ static std::vector<ValueFlow::LifetimeToken> getLifetimeTokens(const Token* tok,
|
|||
errorPath.emplace_back(varDeclEndToken, "Passed to reference.");
|
||||
return {{tok, true, std::move(errorPath)}};
|
||||
}
|
||||
if (Token::simpleMatch(varDeclEndToken, "=")) {
|
||||
if (Token::Match(varDeclEndToken, "=|{")) {
|
||||
errorPath.emplace_back(varDeclEndToken, "Assigned to reference.");
|
||||
const Token *vartok = varDeclEndToken->astOperand2();
|
||||
const bool temporary = isTemporary(true, vartok, nullptr, true);
|
||||
|
|
|
@ -121,6 +121,7 @@ private:
|
|||
TEST_CASE(returnReference23);
|
||||
TEST_CASE(returnReference24); // #10098
|
||||
TEST_CASE(returnReference25); // #10983
|
||||
TEST_CASE(returnReference26);
|
||||
TEST_CASE(returnReferenceFunction);
|
||||
TEST_CASE(returnReferenceContainer);
|
||||
TEST_CASE(returnReferenceLiteral);
|
||||
|
@ -1649,6 +1650,16 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void returnReference26()
|
||||
{
|
||||
check("const int& f() {\n" // #12153
|
||||
" int x = 234;\n"
|
||||
" int& s{ x };\n"
|
||||
" return s;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Reference to local variable returned.\n", errout.str());
|
||||
}
|
||||
|
||||
void returnReferenceFunction() {
|
||||
check("int& f(int& a) {\n"
|
||||
" return a;\n"
|
||||
|
|
Loading…
Reference in New Issue