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

Clarify docs re fmt::make_format_args #1049

Closed
epruesse opened this issue Feb 21, 2019 · 3 comments
Closed

Clarify docs re fmt::make_format_args #1049

epruesse opened this issue Feb 21, 2019 · 3 comments

Comments

@epruesse
Copy link

epruesse commented Feb 21, 2019

It might be worthwhile to make it very clear in the documentation that make_format_args will not make copies of anything, including named_arg arguments created on-the-fly with fmt::arg().

This looks good naively, will compile, and will actually (seem to) work correctly:

auto args = fmt::make_format_args(fmt::arg("key", value))  // BROKEN
auto msg = fmt::vformat("--{key}--", args);

It does, however, dereference parts of the stack that have been freed already...

Correct would be:

auto key_arg = fmt::arg("key", value);
auto args = fmt::make_format_args(key_arg);
auto msg = fmt::vformat("--{key}--", args);
@vitaut
Copy link
Contributor

vitaut commented Feb 21, 2019

http://fmtlib.net/dev/api.html#_CPPv2N3fmt16make_format_argsEDpRK4Args already says that the returned object stores references

Constructs an format_arg_store object that contains references to arguments and can be implicitly converted to format_args.

but it might be worth clarifying further. PRs are welcome.

@mikelui
Copy link
Contributor

mikelui commented Feb 21, 2019

Added documentation in #1051

@epruesse
Copy link
Author

Thanks @mikelui

@vitaut vitaut closed this as completed Feb 22, 2019
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

No branches or pull requests

3 participants