diff --git a/include/chaiscript/dispatchkit/handle_return.hpp b/include/chaiscript/dispatchkit/handle_return.hpp index e0a3b132..e0d4e3ae 100644 --- a/include/chaiscript/dispatchkit/handle_return.hpp +++ b/include/chaiscript/dispatchkit/handle_return.hpp @@ -126,7 +126,7 @@ namespace chaiscript { struct Handle_Return_Ref { template static Boxed_Value handle(T &&r) { - return Boxed_Value(std::cref(r), true); + return Boxed_Value(std::cref(r), false); } }; diff --git a/unittests/map_keys_vector_push_back.chai b/unittests/map_keys_vector_push_back.chai new file mode 100644 index 00000000..2310e846 --- /dev/null +++ b/unittests/map_keys_vector_push_back.chai @@ -0,0 +1,29 @@ +// Regression test for issue #594 +// Map keys pushed into a vector via .first should remain valid +// after the map goes out of scope. + +def keys(Map map) +{ + var v = Vector(); + for( i : map ) + { + v.push_back(i.first); + } + return v; +} + +var k = Vector(); +if ( true ) +{ + var m = ["a":"x", "b":"y", "c":"z"]; + k = keys(m); +} + +// After the map is out of scope, the keys should still be valid strings +assert_equal(3, k.size()) + +// Verify each element is a non-empty string +for (elem : k) +{ + assert_true(elem.size() > 0) +}