-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix FMT_COMPILE()
with custom types
#2326
Fix FMT_COMPILE()
with custom types
#2326
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
test/compile-test.cc
Outdated
struct spec_handler { | ||
formatter& f; | ||
basic_format_parse_context<char>& context; | ||
|
||
void on_error(const char* msg) { FMT_THROW(format_error(msg)); } | ||
FMT_CONSTEXPR void on_fill(basic_string_view<char> fill) { | ||
f.specs.fill = fill; | ||
} | ||
FMT_CONSTEXPR void on_align(align_t align) { f.specs.align = align; } | ||
FMT_CONSTEXPR void on_width(int width) { f.specs.width = width; } | ||
FMT_CONSTEXPR void on_precision(int) {} | ||
FMT_CONSTEXPR void end_precision() {} | ||
template <typename Id> | ||
FMT_CONSTEXPR detail::arg_ref<char> make_arg_ref(Id arg_id) { | ||
context.check_arg_id(arg_id); | ||
return detail::arg_ref<char>(arg_id); | ||
} | ||
FMT_CONSTEXPR detail::arg_ref<char> make_arg_ref( | ||
basic_string_view<char> arg_id) { | ||
context.check_arg_id(arg_id); | ||
return detail::arg_ref<char>(arg_id); | ||
} | ||
FMT_CONSTEXPR detail::arg_ref<char> make_arg_ref(detail::auto_id) { | ||
return detail::arg_ref<char>(context.next_arg_id()); | ||
} | ||
template <typename Id> FMT_CONSTEXPR void on_dynamic_width(Id arg_id) { | ||
f.width_ref = make_arg_ref(arg_id); | ||
} | ||
template <typename Id> FMT_CONSTEXPR void on_dynamic_precision(Id) {} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit of an overkill for the test. Let's do some basic parsing instead of relying on internal API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, commits 1+2 then, dropping the 3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, could you update the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, I will do so, but maybe an hour later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Good catch, added to changelog in 9bb406d. |
cd72ce7
to
7bdc3fd
Compare
Thank you! |
By reading the changelog for upcoming release, I realized that it does not mention one of the major breaking change of custom formatters for compile-time formatting -
const
-qualifiedformat
method, so I decided to check how do custom formatters work at compile-time and realized that they actually don't work.There are 3 commits, by the complexity of changes from the commit that just fixes the library, to the commit that adds dynamic width handling for the
test_formattable
class in compile-test.cc. The latter two can be removed or squashed into the first one, on demand. This time I cannot use custom formatters fromchrono.h
because they usememory_buffer
and it's not ready to be used at compile-time yet.