Commit 1813ca3f authored by Philip Pronin's avatar Philip Pronin Committed by Facebook Github Bot

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
parent c78f92a0
...@@ -466,6 +466,7 @@ class Function final : private detail::function::FunctionTraits<FunctionType> { ...@@ -466,6 +466,7 @@ class Function final : private detail::function::FunctionTraits<FunctionType> {
// (i.e., `template <typename Fun> Function(Fun&&)`). // (i.e., `template <typename Fun> Function(Fun&&)`).
Function(Function&) = delete; Function(Function&) = delete;
Function(const Function&) = delete; Function(const Function&) = delete;
Function(const Function&&) = delete;
/** /**
* Move constructor * Move constructor
......
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