Fix fallback to runtime API from compile-time API#2143
Merged
vitaut merged 3 commits intofmtlib:masterfrom Mar 4, 2021
Merged
Conversation
…PI define, add test
vitaut
requested changes
Feb 28, 2021
Contributor
There was a problem hiding this comment.
Thanks for the PR. Looks good but I don't think we should provide a way to disable the fallback.
vitaut
reviewed
Mar 2, 2021
include/fmt/compile.h
Outdated
Comment on lines
+847
to
+861
| constexpr auto compiled = detail::compile<Args...>(S()); | ||
| #ifdef __cpp_if_constexpr | ||
| if constexpr (std::is_same<remove_cvref_t<decltype(compiled)>, | ||
| detail::unknown_format>()) { | ||
| auto it = | ||
| format_to(detail::truncating_iterator<OutputIt>(out, n), | ||
| static_cast<basic_string_view<typename S::char_type>>(S()), | ||
| std::forward<Args>(args)...); | ||
| return {it.base(), it.count()}; | ||
| } else { | ||
| auto it = format_to(detail::truncating_iterator<OutputIt>(out, n), compiled, | ||
| std::forward<Args>(args)...); | ||
| return {it.base(), it.count()}; | ||
| } | ||
| #else |
Contributor
There was a problem hiding this comment.
Can we replace all of these by forwarding S to format_to call below which will handle fallback?
Contributor
Author
There was a problem hiding this comment.
Yes, we can. It will create one more template instantiation, but it shouldn't be tough.
So, it's done.
…e API instead of compiling it inside format_to_n(), to eliminate code duplication
Contributor
|
Thank you! |
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Right now, when {fmt} fails to prepare compiled format for format string (using
FMT_COMPILEor_cf) it also fails to report about that clearly. Here is an example - https://godbolt.org/z/G1ETdc.There were some attempts to make the error a bit clearer, but as it turned out {fmt} should fall back to the runtime API in those cases. This PR adds that fallback.
Some points for the PR: