From 875a3f47e7864208c21f482102dc01e4346c184c Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Sat, 1 Mar 2014 16:30:59 +0100 Subject: [PATCH] Ticket #5478: Only functions and equal operators might return a temporary. --- lib/checkautovariables.cpp | 3 +++ test/testautovariables.cpp | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 63cfea14b..c8d7d7763 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -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; diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 1ba4d423b..22924f3b4 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -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)