Skip to content

Commit d0eb576

Browse files
committed
apacheGH-49841: [C++] Fix macOS 12.3 SDK build by using __cpp_lib_int_pow2
The macOS 12.3 SDK build failed with "no member named 'log2p1' in namespace 'std'". The Apple clang workaround selects std::log2p1 when __cpp_lib_bitops is undefined, but that macro covers popcount and friends, not std::bit_width. Use __cpp_lib_int_pow2, which covers std::bit_width and std::has_single_bit and is undefined on 11.3, defined on 12.3. Signed-off-by: 1fanwang <[email protected]>
1 parent 3ad410b commit d0eb576

5 files changed

Lines changed: 10 additions & 5 deletions

File tree

‎cpp/src/arrow/util/align_util.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ inline BitmapWordAlignParams BitmapWordAlign(const uint8_t* data, int64_t bit_of
4747
// TODO: We can remove this condition once CRAN upgrades its macOS
4848
// SDK from 11.3.
4949
// __apple_build_version__ should be defined only on Apple clang
50-
#if defined(__apple_build_version__) && !defined(__cpp_lib_bitops)
50+
// std::has_single_bit is guarded by __cpp_lib_int_pow2, not __cpp_lib_bitops
51+
#if defined(__apple_build_version__) && !defined(__cpp_lib_int_pow2)
5152
static_assert((ALIGN_IN_BYTES != 0) && ((ALIGN_IN_BYTES & (ALIGN_IN_BYTES - 1)) == 0),
5253
"ALIGN_IN_BYTES should be a positive power of two");
5354
#else

‎cpp/src/arrow/util/bit_util.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ static inline int Log2(uint64_t x) {
145145
// TODO: We can remove this condition once CRAN upgrades its macOS
146146
// SDK from 11.3.
147147
// __apple_build_version__ should be defined only on Apple clang
148-
#if defined(__apple_build_version__) && !defined(__cpp_lib_bitops)
148+
// std::bit_width is guarded by __cpp_lib_int_pow2, not __cpp_lib_bitops
149+
#if defined(__apple_build_version__) && !defined(__cpp_lib_int_pow2)
149150
return std::log2p1(x - 1);
150151
#else
151152
return std::bit_width(x - 1);

‎cpp/src/arrow/util/rle_encoding_test.cc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,8 @@ TEST(BitRle, Random) {
945945
// TODO: We can remove this condition once CRAN upgrades its macOS
946946
// SDK from 11.3.
947947
// __apple_build_version__ should be defined only on Apple clang
948-
#if defined(__apple_build_version__) && !defined(__cpp_lib_bitops)
948+
// std::bit_width is guarded by __cpp_lib_int_pow2, not __cpp_lib_bitops
949+
#if defined(__apple_build_version__) && !defined(__cpp_lib_int_pow2)
949950
if (!CheckRoundTrip(values, std::log2p1(values.size()))) {
950951
#else
951952
if (!CheckRoundTrip(values, std::bit_width(values.size()))) {

‎cpp/src/parquet/chunker_internal.cc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ uint64_t CalculateMask(int64_t min_chunk_size, int64_t max_chunk_size, int norm_
8989
// TODO: We can remove this condition once CRAN upgrades its macOS
9090
// SDK from 11.3.
9191
// __apple_build_version__ should be defined only on Apple clang
92-
#if defined(__apple_build_version__) && !defined(__cpp_lib_bitops)
92+
// std::bit_width is guarded by __cpp_lib_int_pow2, not __cpp_lib_bitops
93+
#if defined(__apple_build_version__) && !defined(__cpp_lib_int_pow2)
9394
auto target_bits = std::log2p1(static_cast<uint64_t>(target_size));
9495
#else
9596
auto target_bits = std::bit_width(static_cast<uint64_t>(target_size));

‎cpp/src/parquet/encoder.cc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,8 @@ void DeltaBitPackEncoder<DType>::FlushBlock() {
11721172
// TODO: We can remove this condition once CRAN upgrades its macOS
11731173
// SDK from 11.3.
11741174
// __apple_build_version__ should be defined only on Apple clang
1175-
#if defined(__apple_build_version__) && !defined(__cpp_lib_bitops)
1175+
// std::bit_width is guarded by __cpp_lib_int_pow2, not __cpp_lib_bitops
1176+
#if defined(__apple_build_version__) && !defined(__cpp_lib_int_pow2)
11761177
const auto bit_width = bit_width_data[i] =
11771178
std::log2p1(static_cast<UT>(max_delta) - static_cast<UT>(min_delta));
11781179
#else

0 commit comments

Comments
 (0)