From 1813ca3f3ec3cd72b6a938d2d561fe71ad5a76a7 Mon Sep 17 00:00:00 2001 From: Philip Pronin Date: Fri, 2 Sep 2016 09:51:19 -0700 Subject: [PATCH] delete const rvalue reference ctor of folly::Function Summary: This code compiles and is causing stack overflow at runtime: ``` using F = folly::Function; 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 F(Fun&&)` (where `Fun = F const`) and we end up in an infinite `F(Fun&&) <-> F(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 | 1 + 1 file changed, 1 insertion(+) diff --git a/folly/Function.h b/folly/Function.h index 570f5b8e..91a8c6a1 100644 --- a/folly/Function.h +++ b/folly/Function.h @@ -466,6 +466,7 @@ class Function final : private detail::function::FunctionTraits { // (i.e., `template Function(Fun&&)`). Function(Function&) = delete; Function(const Function&) = delete; + Function(const Function&&) = delete; /** * Move constructor -- 2.34.1