Merge pull request #245 from simartin/ticket_5478

Ticket #5478: Only functions and equal operators might return a temporary
This commit is contained in:
Daniel Marjamäki 2014-03-02 14:53:25 +01:00
commit 4dee3da1bd
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(); const Function *function = tok->function();
if (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) == "&"; retref = function->tokenDef->strAt(-1) == "&";
if (!retref) { if (!retref) {
const Token *start = function->retDef; const Token *start = function->retDef;

View File

@ -107,6 +107,8 @@ private:
TEST_CASE(testglobalnamespace); TEST_CASE(testglobalnamespace);
TEST_CASE(returnParameterAddress); TEST_CASE(returnParameterAddress);
TEST_CASE(testconstructor); // ticket #5478 - crash
} }
@ -814,6 +816,15 @@ private:
ASSERT_EQUALS("", errout.str()); 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) REGISTER_TEST(TestAutoVariables)