Fix 10098: false negative: 'Reference to temporary returned.' not detected with class (#3509)
This commit is contained in:
parent
7f04658585
commit
876702c4f2
|
@ -371,6 +371,8 @@ bool isTemporary(bool cpp, const Token* tok, const Library* library, bool unknow
|
|||
return false;
|
||||
if (const Function * f = ftok->function()) {
|
||||
return !Function::returnsReference(f, true);
|
||||
} else if (ftok->type()) {
|
||||
return true;
|
||||
} else if (library) {
|
||||
std::string returnType = library->returnValueType(ftok);
|
||||
return !returnType.empty() && returnType.back() != '&';
|
||||
|
|
|
@ -118,6 +118,7 @@ private:
|
|||
TEST_CASE(returnReference21); // #9530
|
||||
TEST_CASE(returnReference22);
|
||||
TEST_CASE(returnReference23);
|
||||
TEST_CASE(returnReference24); // #10098
|
||||
TEST_CASE(returnReferenceFunction);
|
||||
TEST_CASE(returnReferenceContainer);
|
||||
TEST_CASE(returnReferenceLiteral);
|
||||
|
@ -1462,6 +1463,17 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void returnReference24()
|
||||
{
|
||||
check("struct A {\n"
|
||||
" A() {}\n"
|
||||
"};\n"
|
||||
"const A& a() {\n"
|
||||
" return A();\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Reference to temporary returned.\n", errout.str());
|
||||
}
|
||||
|
||||
void returnReferenceFunction() {
|
||||
check("int& f(int& a) {\n"
|
||||
" return a;\n"
|
||||
|
|
Loading…
Reference in New Issue