Ticket #5478: Only functions and equal operators might return a temporary.

This commit is contained in:
Simon Martin 2014-03-01 16:30:59 +01:00
parent bef4739853
commit 875a3f47e7
2 changed files with 14 additions and 0 deletions

View File

@ -292,6 +292,9 @@ bool CheckAutoVariables::returnTemporary(const Token *tok) const
const Function *function = tok->function();
if (function) {
// Ticket #5478: Only functions or operator equal might return a temporary
if (function->type != Function::eOperatorEqual && function->type != Function::eFunction)
return false;
retref = function->tokenDef->strAt(-1) == "&";
if (!retref) {
const Token *start = function->retDef;

View File

@ -107,6 +107,8 @@ private:
TEST_CASE(testglobalnamespace);
TEST_CASE(returnParameterAddress);
TEST_CASE(testconstructor); // ticket #5478 - crash
}
@ -809,6 +811,15 @@ private:
ASSERT_EQUALS("", errout.str());
}
void testconstructor() { // Ticket #5478 - crash while checking a constructor
check("class const_tree_iterator {\n"
" const_tree_iterator(bool (*_incream)(node_type*&)) {}\n"
" const_tree_iterator& parent() {\n"
" return const_tree_iterator(foo);\n"
" }\n"
"};");
}
};
REGISTER_TEST(TestAutoVariables)