diff --git a/base/base_tests/exception_tests.cpp b/base/base_tests/exception_tests.cpp index e9eac58fab..1b0043db31 100644 --- a/base/base_tests/exception_tests.cpp +++ b/base/base_tests/exception_tests.cpp @@ -3,6 +3,7 @@ #include "base/exception.hpp" #include +#include namespace { @@ -22,6 +23,14 @@ void FuncThrowsRootExceptionVoid(int) { throw RootException("RootException", "Ro void FuncThrowsExceptionVoid() { throw std::exception(); } void FuncThrowsNumberVoid() { throw 1; }; +std::string const & ReturnsByRef(std::string const & str) +{ + bool exception = true; + return ExceptionCatcher( + "ReturnsByRef().", exception, + [](std::string const & str) -> std::string const & { return str; }, str); +} + UNIT_TEST(ExceptionCatcher_FunctionsWithoutArgs) { bool exception = false; @@ -147,4 +156,11 @@ UNIT_TEST(ExceptionCatcher_FunctionsReturnVoid) ExceptionCatcher("Function returns void.", exception, FuncThrowsExceptionVoid); ExceptionCatcher("Function returns void.", exception, FuncThrowsNumberVoid); } + +UNIT_TEST(ExceptionCatcher_PreventReturningRefOnLocaleTemporaryObj) +{ + std::string const str = "A string"; + auto const returnedStr = ReturnsByRef(str); + TEST_EQUAL(str, returnedStr, ()); +} } // namespace