Fix issue 9482: False positive: Reference to temporary returned using trailing return type (#2413)
This commit is contained in:
parent
2bdb7dc236
commit
9cb39b1d7e
|
@ -2279,6 +2279,9 @@ bool Function::returnsReference(const Function* function, bool unknown)
|
||||||
start = start->next();
|
start = start->next();
|
||||||
if (start->tokAt(1) == defEnd && !start->type() && !start->isStandardType())
|
if (start->tokAt(1) == defEnd && !start->type() && !start->isStandardType())
|
||||||
return unknown;
|
return unknown;
|
||||||
|
// TODO: Try to deduce the type of the expression
|
||||||
|
if (Token::Match(start, "decltype|typeof"))
|
||||||
|
return unknown;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,7 @@ private:
|
||||||
TEST_CASE(returnReference16); // #9433
|
TEST_CASE(returnReference16); // #9433
|
||||||
TEST_CASE(returnReference16); // #9433
|
TEST_CASE(returnReference16); // #9433
|
||||||
TEST_CASE(returnReference17); // #9461
|
TEST_CASE(returnReference17); // #9461
|
||||||
|
TEST_CASE(returnReference18); // #9482
|
||||||
TEST_CASE(returnReferenceFunction);
|
TEST_CASE(returnReferenceFunction);
|
||||||
TEST_CASE(returnReferenceContainer);
|
TEST_CASE(returnReferenceContainer);
|
||||||
TEST_CASE(returnReferenceLiteral);
|
TEST_CASE(returnReferenceLiteral);
|
||||||
|
@ -1297,6 +1298,15 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void returnReference18() {
|
||||||
|
check("template<class T>\n"
|
||||||
|
"auto f(T& x) -> decltype(x);\n"
|
||||||
|
"int& g(int* x) {\n"
|
||||||
|
" return f(*x);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void returnReferenceFunction() {
|
void returnReferenceFunction() {
|
||||||
check("int& f(int& a) {\n"
|
check("int& f(int& a) {\n"
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
|
|
Loading…
Reference in New Issue