(Wangle) Align lambdaBuf_
[folly.git] / folly / futures / detail / Core.h
index efbf2616ebf821e5bb32bb063d61be9f76f3330e..252af04a56071fae5b039d1c074b2a5c1e735d7d 100644 (file)
@@ -148,7 +148,7 @@ class Core {
 
       // Move the lambda into the Core if it fits
       if (sizeof(LambdaBufHelper<F>) <= lambdaBufSize) {
-        auto funcLoc = static_cast<LambdaBufHelper<F>*>((void*)lambdaBuf_);
+        auto funcLoc = reinterpret_cast<LambdaBufHelper<F>*>(&lambdaBuf_);
         new (funcLoc) LambdaBufHelper<F>(std::forward<F>(func));
         callback_ = std::ref(*funcLoc);
       } else {
@@ -366,7 +366,7 @@ class Core {
 
   // lambdaBuf occupies exactly one cache line
   static constexpr size_t lambdaBufSize = 8 * sizeof(void*);
-  char lambdaBuf_[lambdaBufSize];
+  typename std::aligned_storage<lambdaBufSize>::type lambdaBuf_;
   // place result_ next to increase the likelihood that the value will be
   // contained entirely in one cache line
   folly::Optional<Try<T>> result_;