From d6a27b28486331975bb538ddce4213301d913a1f Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Mon, 6 Nov 2017 11:42:48 -0800 Subject: [PATCH] Value-initialize the Data union member of folly::Function 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 | 2 +- folly/test/FunctionTest.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/folly/Function.h b/folly/Function.h index b8a287dd..ec145688 100644 --- a/folly/Function.h +++ b/folly/Function.h @@ -529,7 +529,7 @@ class Function final : private detail::function::FunctionTraits { // 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}; diff --git a/folly/test/FunctionTest.cpp b/folly/test/FunctionTest.cpp index a062d933..34217a2c 100644 --- a/folly/test/FunctionTest.cpp +++ b/folly/test/FunctionTest.cpp @@ -1095,3 +1095,7 @@ TEST(Function, CtorWithCopy) { EXPECT_TRUE(noexcept(Function(lx))); EXPECT_FALSE(noexcept(Function(ly))); } + +TEST(Function, Bug_T23346238) { + const Function nullfun; +} -- 2.34.1