Skip to content

Commit fb5a4f6

Browse files
ARROW-15520: [C++] Qualify arrow_vendored::date::format() for C++20 compatibility
As explained in ARROW-15520, these unqualified calls to `format()` are ambiguous in the C++20 Standard. The `using`-declaration `using arrow_vendored::date::format;` makes the compiler consider the desired overload, but it doesn't automatically win. Argument-Dependent Lookup also considers `std::format()` because the arguments are `std::chrono::duration` types (and `<chrono>` includes `<format>` in MSVC's implementation). A very recent change to `std::format()`'s signature in a C++20 Defect Report makes it an equally good match as the desired `arrow_vendored::date::format()` overload, so the compiler emits an ambiguity error. The fix is simple, although slightly verbose - the code simply needs to explicitly qualify each call, in order to defend against Argument-Dependent Lookup. The fix is also perfectly backwards-compatible (i.e. it works in previous Standard versions, and with all other platforms). (Also as mentioned in ARROW-15520, although this requires building Apache Arrow with non-default settings to use the latest C++ Standard version, this change is good for future-proofing and will make it easier for the MSVC team to continue validation that prevents toolset regressions that could affect Apache Arrow and other projects.) Closes #12317 from StephanTLavavej/cxx20-format Lead-authored-by: Stephan T. Lavavej <stl@microsoft.com> Co-authored-by: Antoine Pitrou <pitrou@free.fr> Co-authored-by: Stephan T. Lavavej <stl@nuwen.net> Signed-off-by: Antoine Pitrou <antoine@python.org>
1 parent 56386a4 commit fb5a4f6

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

cpp/src/arrow/array/diff.cc

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -639,42 +639,44 @@ class MakeFormatterImpl {
639639
auto fmt = fmt_str.c_str();
640640
auto unit = checked_cast<const T&>(*array.type()).unit();
641641
auto value = checked_cast<const NumericArray<T>&>(array).Value(index);
642-
using arrow_vendored::date::format;
642+
// Using unqualified `format` directly would produce ambiguous
643+
// lookup because of `std::format` (ARROW-15520).
644+
namespace avd = arrow_vendored::date;
643645
using std::chrono::nanoseconds;
644646
using std::chrono::microseconds;
645647
using std::chrono::milliseconds;
646648
using std::chrono::seconds;
647649
if (AddEpoch) {
648-
static arrow_vendored::date::sys_days epoch{arrow_vendored::date::jan / 1 / 1970};
650+
static avd::sys_days epoch{avd::jan / 1 / 1970};
649651

650652
switch (unit) {
651653
case TimeUnit::NANO:
652-
*os << format(fmt, static_cast<nanoseconds>(value) + epoch);
654+
*os << avd::format(fmt, static_cast<nanoseconds>(value) + epoch);
653655
break;
654656
case TimeUnit::MICRO:
655-
*os << format(fmt, static_cast<microseconds>(value) + epoch);
657+
*os << avd::format(fmt, static_cast<microseconds>(value) + epoch);
656658
break;
657659
case TimeUnit::MILLI:
658-
*os << format(fmt, static_cast<milliseconds>(value) + epoch);
660+
*os << avd::format(fmt, static_cast<milliseconds>(value) + epoch);
659661
break;
660662
case TimeUnit::SECOND:
661-
*os << format(fmt, static_cast<seconds>(value) + epoch);
663+
*os << avd::format(fmt, static_cast<seconds>(value) + epoch);
662664
break;
663665
}
664666
return;
665667
}
666668
switch (unit) {
667669
case TimeUnit::NANO:
668-
*os << format(fmt, static_cast<nanoseconds>(value));
670+
*os << avd::format(fmt, static_cast<nanoseconds>(value));
669671
break;
670672
case TimeUnit::MICRO:
671-
*os << format(fmt, static_cast<microseconds>(value));
673+
*os << avd::format(fmt, static_cast<microseconds>(value));
672674
break;
673675
case TimeUnit::MILLI:
674-
*os << format(fmt, static_cast<milliseconds>(value));
676+
*os << avd::format(fmt, static_cast<milliseconds>(value));
675677
break;
676678
case TimeUnit::SECOND:
677-
*os << format(fmt, static_cast<seconds>(value));
679+
*os << avd::format(fmt, static_cast<seconds>(value));
678680
break;
679681
}
680682
};

0 commit comments

Comments
 (0)