From cf1c637daf3a0792df470277ab8f833fc7658cbb Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Wed, 3 Aug 2016 17:22:57 -0700 Subject: [PATCH] Don't name a member small Summary: Because, if you aren't compiling with `WIN32_LEAN_AND_MEAN`, including `WinSock2.h` will result in `small` being `#define`'d as `char`. The best way to work around the issue is to simply change the name of the member to something else. It would also have been possible to solve the problem by adding a section to `folly/portability/Windows.h`, but that would have required including that header in `folly/Function.h`, which there really is no reason to do. Reviewed By: yfeldblum Differential Revision: D3666417 fbshipit-source-id: 21c0363a4b77bb01e4ec20b2fc625c40729879c3 --- folly/Function.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/folly/Function.h b/folly/Function.h index 9d9403ba..570f5b8e 100644 --- a/folly/Function.h +++ b/folly/Function.h @@ -242,13 +242,13 @@ enum class Op { MOVE, NUKE, FULL, HEAP }; union Data { void* big; - std::aligned_storage<6 * sizeof(void*)>::type small; + std::aligned_storage<6 * sizeof(void*)>::type tiny; }; template ::type> using IsSmall = std::integral_constant< bool, - (sizeof(FunT) <= sizeof(Data::small) && + (sizeof(FunT) <= sizeof(Data::tiny) && // Same as is_nothrow_move_constructible, but w/ no template instantiation. noexcept(FunT(std::declval())) )>; @@ -288,7 +288,7 @@ struct FunctionTraits { template static ReturnType callSmall(Data& p, Args&&... args) { return static_cast((*static_cast( - static_cast(&p.small)))(static_cast(args)...)); + static_cast(&p.tiny)))(static_cast(args)...)); } template @@ -329,7 +329,7 @@ struct FunctionTraits { template static ReturnType callSmall(Data& p, Args&&... args) { return static_cast((*static_cast( - static_cast(&p.small)))(static_cast(args)...)); + static_cast(&p.tiny)))(static_cast(args)...)); } template @@ -359,11 +359,11 @@ template bool execSmall(Op o, Data* src, Data* dst) { switch (o) { case Op::MOVE: - ::new (static_cast(&dst->small)) - Fun(std::move(*static_cast(static_cast(&src->small)))); + ::new (static_cast(&dst->tiny)) + Fun(std::move(*static_cast(static_cast(&src->tiny)))); FOLLY_FALLTHROUGH; case Op::NUKE: - static_cast(static_cast(&src->small))->~Fun(); + static_cast(static_cast(&src->tiny))->~Fun(); break; case Op::FULL: return true; @@ -433,7 +433,7 @@ class Function final : private detail::function::FunctionTraits { Function(Fun&& fun, SmallTag) noexcept { using FunT = typename std::decay::type; if (!detail::function::isNullPtrFn(fun)) { - ::new (static_cast(&data_.small)) FunT(static_cast(fun)); + ::new (static_cast(&data_.tiny)) FunT(static_cast(fun)); call_ = &Traits::template callSmall; exec_ = &detail::function::execSmall; } -- 2.34.1