From e4c59d4de8b418ff3121f1f4116b3b94063be0e9 Mon Sep 17 00:00:00 2001 From: jackylee-ch Date: Mon, 18 May 2026 16:52:42 +0800 Subject: [PATCH] [Velox] Fix Arrow vendored datetime build failure on macOS C++20 libc++ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Arrow 15.0.0 ships a vendored copy of Howard Hinnant's date library. On macOS with `-std=c++20`, libc++'s `std::chrono` exposes its own `operator<<` for `sys_time` and related clock types that collides with `date::operator<<` pulled in via `using namespace date;` / `using date::operator<<;` in `vendored/datetime/tz.cpp` and `vendored/datetime/tz_private.h`. The resulting ambiguous overload resolution fails the Arrow CPP build: cpp/src/arrow/vendored/datetime/tz.cpp: error: use of overloaded operator '<<' is ambiguous (with operand types 'std::ostream' and 'const date::sys_seconds') Linux libstdc++ does not expose the conflicting `chrono::operator<<` so the build is unaffected there. Add `ep/build-velox/src/fix_vendored_datetime_operator.patch` that replaces the ADL-driven `os << timepoint` call sites with an explicit qualified call `date::operator<<(os, timepoint)` so the vendored overload is selected unambiguously regardless of what `std::chrono` provides. Apply the patch from `dev/build-arrow.sh::prepare_arrow_build` right after the existing Arrow patches (`modify_arrow.patch`, `modify_arrow_dataset_scan_option.patch`, `cmake-compatibility.patch`, `support_ibm_power.patch`). Two callsites are touched: - tz.cpp:2734 in `operator<<(std::ostream&, const leap_second&)` — drops the `using namespace date;` and calls `date::operator<<(os, x.date_)`. - tz_private.h:291 in `operator<<(std::ostream&, const transition&)` — drops `using date::operator<<;` and calls `date::operator<<(os, t.timepoint)`. Verification: - macOS 14 arm64 with Apple Clang 17, `-std=c++20`: Arrow CPP build reaches successful link of `libarrow.a` and the JNI cdata/dataset shared libraries; before the patch the build aborted at the first TU including `tz_private.h`. - Linux x86_64 build is unaffected because the patched code paths only fail on libc++. Local Ubuntu 22.04 build verified clean. --- dev/build-arrow.sh | 3 ++ .../src/fix_vendored_datetime_operator.patch | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 ep/build-velox/src/fix_vendored_datetime_operator.patch diff --git a/dev/build-arrow.sh b/dev/build-arrow.sh index 54c6faaf331..8bb2a19b3fe 100755 --- a/dev/build-arrow.sh +++ b/dev/build-arrow.sh @@ -34,6 +34,9 @@ function prepare_arrow_build() { patch -p1 < $CURRENT_DIR/../ep/build-velox/src/modify_arrow_dataset_scan_option.patch patch -p1 < $CURRENT_DIR/../ep/build-velox/src/cmake-compatibility.patch patch -p1 < $CURRENT_DIR/../ep/build-velox/src/support_ibm_power.patch + # Fix C++20 operator<< ambiguity in Arrow's vendored Howard Hinnant date + # library on macOS libc++ (sys_time overload conflicts with date::operator<<). + patch -p1 < $CURRENT_DIR/../ep/build-velox/src/fix_vendored_datetime_operator.patch popd } diff --git a/ep/build-velox/src/fix_vendored_datetime_operator.patch b/ep/build-velox/src/fix_vendored_datetime_operator.patch new file mode 100644 index 00000000000..3843a9ee68b --- /dev/null +++ b/ep/build-velox/src/fix_vendored_datetime_operator.patch @@ -0,0 +1,37 @@ +Fix C++20 operator<< ambiguity in Arrow's vendored Howard Hinnant date library. + +On macOS libc++ with -std=c++20, std::chrono's own operator<< for sys_time +overloads conflict with the vendored `date::operator<<` pulled in via +`using date::operator<<` / `using namespace date`, producing an ambiguous +overload resolution error when streaming sys_seconds/sys_time values. + +Replace the ADL-driven `<<` call sites with an explicit qualified call +`date::operator<<(os, timepoint)` so the vendored overload is selected +unambiguously regardless of what std::chrono provides. + +diff --git a/cpp/src/arrow/vendored/datetime/tz.cpp b/cpp/src/arrow/vendored/datetime/tz.cpp +--- a/cpp/src/arrow/vendored/datetime/tz.cpp ++++ b/cpp/src/arrow/vendored/datetime/tz.cpp +@@ -2734,8 +2734,7 @@ + std::ostream& + operator<<(std::ostream& os, const leap_second& x) + { +- using namespace date; +- return os << x.date_ << " +"; ++ return date::operator<<(os, x.date_) << " +"; + } + + #if USE_OS_TZDB +diff --git a/cpp/src/arrow/vendored/datetime/tz_private.h b/cpp/src/arrow/vendored/datetime/tz_private.h +--- a/cpp/src/arrow/vendored/datetime/tz_private.h ++++ b/cpp/src/arrow/vendored/datetime/tz_private.h +@@ -291,8 +291,7 @@ + std::ostream& + operator<<(std::ostream& os, const transition& t) + { +- using date::operator<<; +- os << t.timepoint << "Z "; ++ date::operator<<(os, t.timepoint) << "Z "; + if (t.info->offset >= std::chrono::seconds{0}) + os << '+'; + os << make_time(t.info->offset);