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 b8a287dd9d0934f415fc7abfaeb1ee274df93211..ec145688b75ca0316e184db6c915277acbcc386b 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 a062d9339ecffa40e0a5368e0776f8c8178465d2..34217a2c825d028e318ed940cdfb5cfd61920dc2 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;
+}