Skip to content

Commit

Permalink
Fix compilation of folly/Bits.h with MSVC
Browse files Browse the repository at this point in the history
Summary:
This diff fixes compilation of folly/Bits.h with MSVC by checking for both <bit>/C++ version and checking for the __cpp_lib flag for std::bit_set. When compiling F14Table.cpp with MSVC and C++20, the <bit> check was passing while the check for __cpp_lib_bit_cast was failing.

This also corrects two uses of bit_cast to use folly::bit_cast.

Reviewed By: Gownta

Differential Revision: D49357730

fbshipit-source-id: c741a7b9f4b1862af6c0110a52d720337ff58748
  • Loading branch information
Eric Griffith authored and facebook-github-bot committed Sep 21, 2023
1 parent f52e6aa commit abbd46b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion folly/hash/Hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ struct hasher<T*> {
using folly_is_avalanching = hasher<std::uintptr_t>::folly_is_avalanching;

size_t operator()(T* key) const {
return Hash()(bit_cast<std::uintptr_t>(key));
return Hash()(folly::bit_cast<std::uintptr_t>(key));
}
};

Expand Down
4 changes: 2 additions & 2 deletions folly/lang/Bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@
#include <folly/lang/Assume.h>
#include <folly/portability/Builtins.h>

#if __has_include(<bit>) && __cplusplus >= 202002L
#if __has_include(<bit>) && (__cplusplus >= 202002L || (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L))
#include <bit>
#endif

namespace folly {

#ifdef __cpp_lib_bit_cast
#if defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L

using std::bit_cast;

Expand Down
3 changes: 2 additions & 1 deletion folly/synchronization/DistributedMutex-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,8 @@ FOLLY_ALWAYS_INLINE std::uintptr_t tryWake(
// we need release here because of the write to waker_ and also because we
// are unlocking the mutex, the thread we do the handoff to here should
// see the modified data
new (&waiter->metadata_) Metadata{waker, bit_cast<uintptr_t>(sleepers)};
new (&waiter->metadata_)
Metadata{waker, folly::bit_cast<uintptr_t>(sleepers)};
waiter->futex_.store(kWake, std::memory_order_release);
return 0;
}
Expand Down

0 comments on commit abbd46b

Please sign in to comment.