delete const rvalue reference ctor of folly::Function v2016.09.05.00
authorPhilip Pronin <philipp@fb.com>
Fri, 2 Sep 2016 16:51:19 +0000 (09:51 -0700)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Fri, 2 Sep 2016 16:53:32 +0000 (09:53 -0700)
commit1813ca3f3ec3cd72b6a938d2d561fe71ad5a76a7
treeca053fbacdfd37c7c8829fbd36b1fd2aa0482e5e
parentc78f92a01dfdd0cc4eff81e90dd9e0832fd77bfc
delete const rvalue reference ctor of folly::Function

Summary:
This code compiles and is causing stack overflow at runtime:

```
using F = folly::Function<void()>;
void foo(F);

F bar;
auto baz = [bar = std::move(bar)] {
  foo(std::move(bar));
};
baz();
```

The bug there is that `baz` is missing `mutable` keyword, so when
constructing argument for `foo`, `F(const F&&)` is called, which is selecting
`template <typename Fun> F(Fun&&)` (where `Fun = F const`) and we end up in
an infinite `F<Fun>(Fun&&) <-> F<Fun>(Fun&&, SmallTag|HeapTag)` cycle.

This diff transforms this easy-to-make-bug into compile-time error.

Reviewed By: yfeldblum

Differential Revision: D3810269

fbshipit-source-id: f80a18ab02bd0715d692cf67c3c8943f557c2982
folly/Function.h