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
typename Func,
typename = typename std::enable_if<std::is_convertible<
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 Map& map,
const typename Map::key_type& key,
std::addressof(i),
std::addressof(
get_ref_default(m, 2, [&i]() -> const int& { return i; })));
+ // statically disallowed:
+ // get_ref_default(m, 2, [] { return 7; });
}
TEST(MapUtil, get_ptr) {