Skip to content
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

Fixed issue with formatting to an array of chars #1171

Merged
merged 1 commit into from
Jun 12, 2019

Conversation

stryku
Copy link
Contributor

@stryku stryku commented May 21, 2019

It should fix #1169. Added a couple of tests to prevent such issues in the future. Please, let me know if I forgot about any prepared_format::format_to use case.

Copy link
Contributor

@vitaut vitaut left a 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! Mostly looks good, just two comments inline.

include/fmt/prepare.h Outdated Show resolved Hide resolved
@@ -246,14 +246,19 @@ class prepared_format {
}

private:
typedef typename buffer_context<char_type>::type context;
template <typename Range, typename Context, typename... StoreArgs>
auto vformat_to(Range out, format_arg_store<Context, StoreArgs...> args) const
Copy link
Contributor

Choose a reason for hiding this comment

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

vformat* functions should take basic_format_args not format_arg_store.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those are private methods. I've introduced the overload that takes format_arg_store, because calling prepared_format::format_to() with char* as an output iterator, introduced compilation error could not match 'basic_format_args' against 'format_arg_store'. That's why I decided to create the overload, explicitly create basic_format_args there and pass it to the proper vformat implementation.

Does it resolve your doubts or it's still wrong? If it's wrong, what do you propose?

Copy link
Contributor

Choose a reason for hiding this comment

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

The matching error is because template argument deduction doesn't play well with implicit conversion from format_arg_store to format_args. I suggest removing the extra overload and adding braces to force the conversion as it is done in

{internal::make_args_checked(format_str, args...)});

Copy link
Contributor Author

@stryku stryku Jun 11, 2019

Choose a reason for hiding this comment

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

Hmm, I think that's not exactly the case. Braces help here because with such call, compiler doesn't need to deduce context for basic_format_args, thus whole basic_format_args<context> type is known. It's known because Char type known, as well.

basic_format_args<buffer_context<Char>> args) {

In my case, the context type is not known and needs to be deduced, so basic_format_args is not known and can not be deduced because compiler would need to perform implicit conversion.

To handle this, I've added explicit call to basic_format_args ctors. Please check it and let me know if it looks reasonable.

@stryku stryku force-pushed the 1169-format-to-array-of-chars branch 2 times, most recently from c479b5f to aa68b28 Compare June 10, 2019 20:19
@stryku stryku force-pushed the 1169-format-to-array-of-chars branch from aa68b28 to b997955 Compare June 11, 2019 20:04
@vitaut vitaut merged commit 9427f15 into fmtlib:master Jun 12, 2019
@vitaut
Copy link
Contributor

vitaut commented Jun 12, 2019

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fmt::prepare fails to compile formatting to an array of chars
2 participants