Commit cf784212 authored by Tom Jackson's avatar Tom Jackson Committed by Facebook Github Bot 9

prvalues from get_ref_default()'s default functor

Summary: This previously allowed `get_ref_default(map, 4, []{ return 6; })`, even though this would form a reference to a temporary, then **use that invalid reference**.

Reviewed By: yfeldblum

Differential Revision: D3802707

fbshipit-source-id: 384d965f69c9d7b6bd3f011c8eff7fe55be7023a
parent dd6fff71
...@@ -116,7 +116,9 @@ template < ...@@ -116,7 +116,9 @@ template <
typename Func, typename Func,
typename = typename std::enable_if<std::is_convertible< typename = typename std::enable_if<std::is_convertible<
typename std::result_of<Func()>::type, typename std::result_of<Func()>::type,
const typename Map::mapped_type&>::value>::type> const typename Map::mapped_type&>::value>::type,
typename = typename std::enable_if<
std::is_reference<typename std::result_of<Func()>::type>::value>::type>
const typename Map::mapped_type& get_ref_default( const typename Map::mapped_type& get_ref_default(
const Map& map, const Map& map,
const typename Map::key_type& key, const typename Map::key_type& key,
......
...@@ -85,6 +85,8 @@ TEST(MapUtil, get_ref_default_function) { ...@@ -85,6 +85,8 @@ TEST(MapUtil, get_ref_default_function) {
std::addressof(i), std::addressof(i),
std::addressof( std::addressof(
get_ref_default(m, 2, [&i]() -> const int& { return i; }))); get_ref_default(m, 2, [&i]() -> const int& { return i; })));
// statically disallowed:
// get_ref_default(m, 2, [] { return 7; });
} }
TEST(MapUtil, get_ptr) { TEST(MapUtil, get_ptr) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment