Skip to content

Commit

Permalink
fix CancellationState under MSVC
Browse files Browse the repository at this point in the history
Summary: It uses `std::array<CancellationCallback, N>`. But `CancellationCallback` is not default-constructible, and `N` may be zero, and MSVC < v19.31 fails to support this combination.

Reviewed By: Gownta

Differential Revision: D64644003

fbshipit-source-id: 0012977e5ba90f826b5256d2ac3239483ce7cf75
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Oct 23, 2024
1 parent e57ce30 commit e30d4fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1065,8 +1065,7 @@ if (BUILD_TESTS OR BUILD_BENCHMARKS)
TEST atomic_unordered_map_test SOURCES AtomicUnorderedMapTest.cpp
TEST base64_test SOURCES base64_test.cpp
TEST buffered_atomic_test SOURCES BufferedAtomicTest.cpp
TEST cancellation_token_test WINDOWS_DISABLED
SOURCES CancellationTokenTest.cpp
TEST cancellation_token_test SOURCES CancellationTokenTest.cpp
TEST chrono_test SOURCES ChronoTest.cpp
TEST clock_gettime_wrappers_test SOURCES ClockGettimeWrappersTest.cpp
TEST concurrent_bit_set_test SOURCES ConcurrentBitSetTest.cpp
Expand Down
11 changes: 10 additions & 1 deletion folly/CancellationToken-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,16 @@ class FixedMergingCancellationState : public CancellationState {
FOLLY_NODISCARD static CancellationStateTokenPtr create(Ts&&... tokens);

private:
std::array<CancellationCallback, N> callbacks_;
// MSVC < v19.31 does not correctly support std::array<T, 0>; so we improvise
template <typename, size_t>
struct EmptyArray {
explicit EmptyArray(std::initializer_list<int>) noexcept {}
};
using CancellationCallbackArray = conditional_t<
!N,
EmptyArray<CancellationCallback, N>,
std::array<CancellationCallback, N>>;
CancellationCallbackArray callbacks_;
};

template <typename... Data>
Expand Down

0 comments on commit e30d4fb

Please sign in to comment.