Implement folly::launder for MSVC
[folly.git] / folly / Launder.h
index 6a3b976dee649d7fadd38220370039f44c202752..fb0e5f7a71ea5e44f2278cebfc65a18ec5074be5 100644 (file)
@@ -35,6 +35,11 @@ FOLLY_NODISCARD inline T* launder(T* in) noexcept {
   // so the compiler has to assume that it has been changed inside the block.
   __asm__("" : "+r"(in));
   return in;
+#elif defined(_WIN32)
+  // MSVC does not currently have optimizations around const members of structs.
+  // _ReadWriteBarrier() will prevent compiler reordering memory accesses.
+  _ReadWriteBarrier();
+  return in;
 #else
   static_assert(
       false, "folly::launder is not implemented for this environment");