Skip to content

Conversation

@StephanTLavavej
Copy link
Contributor

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.)

@github-actions
Copy link

github-actions bot commented Feb 2, 2022

@github-actions
Copy link

github-actions bot commented Feb 2, 2022

⚠️ Ticket has not been started in JIRA, please click 'Start Progress'.

@pitrou pitrou changed the title ARROW-15520: Qualify arrow_vendored::date::format() for C++20 compatibility ARROW-15520: [C++] Qualify arrow_vendored::date::format() for C++20 compatibility Feb 2, 2022
@StephanTLavavej
Copy link
Contributor Author

Aha, clang-format has rejected overly long lines. (The microsoft/STL repo is also a huge fan of clang-format!) I'll validate and push a commit to fix this.

@StephanTLavavej
Copy link
Contributor Author

Although I could have accepted clang-format's wrapping, it seemed ugly (since it consumes extra lines and makes the code not line up nicely). After seeing that namespace aliases are used elsewhere in the codebase, I introduced one here. For consistency, I changed an extra line to use the new alias, considerably shortening it.

Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @StephanTLavavej . I'll wait for CI and merge if green.

@pitrou pitrou closed this in fb5a4f6 Feb 2, 2022
@ursabot
Copy link

ursabot commented Feb 2, 2022

Benchmark runs are scheduled for baseline = 56386a4 and contender = fb5a4f6. fb5a4f6 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Finished ⬇️0.0% ⬆️0.0%] ec2-t3-xlarge-us-east-2
[Finished ⬇️0.36% ⬆️0.0%] ursa-i9-9960x
[Finished ⬇️0.26% ⬆️0.0%] ursa-thinkcentre-m75q
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python. Runs only benchmarks with cloud = True
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

@StephanTLavavej StephanTLavavej deleted the cxx20-format branch February 6, 2022 22:07
kszucs pushed a commit to kszucs/arrow that referenced this pull request Mar 3, 2022
… 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 apache#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants