Value-initialize the Data union member of folly::Function
authorEric Niebler <eniebler@fb.com>
Mon, 6 Nov 2017 19:42:48 +0000 (11:42 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Mon, 6 Nov 2017 19:51:10 +0000 (11:51 -0800)
Summary: The Data field was not getting value-initialized, leading compilers to complain when value-initializing const folly::Function objects.

Reviewed By: yfeldblum, ot

Differential Revision: D6241712

fbshipit-source-id: 99ce7f6016f6e7d16b1cff7aa51b7bef53ec592d

folly/Function.h
folly/test/FunctionTest.cpp

index b8a287d..ec14568 100644 (file)
@@ -529,7 +529,7 @@ class Function final : private detail::function::FunctionTraits<FunctionType> {
   // invoking undefined behavior. Const-correctness is only violated when
   // `FunctionType` is a const function type (e.g., `int() const`) and `*this`
   // is the result of calling `constCastFunction`.
-  mutable Data data_;
+  mutable Data data_{};
   Call call_{&Traits::uninitCall};
   Exec exec_{&detail::function::uninitNoop};
 
index a062d93..34217a2 100644 (file)
@@ -1095,3 +1095,7 @@ TEST(Function, CtorWithCopy) {
   EXPECT_TRUE(noexcept(Function<void()>(lx)));
   EXPECT_FALSE(noexcept(Function<void()>(ly)));
 }
+
+TEST(Function, Bug_T23346238) {
+  const Function<void()> nullfun;
+}