Skip to content

Doc: Unclear contract for retention of fmt::arg results #2178

Description

@BillyDonahue

Docs for fmt::arg() seem to indicate that the returned object my depend on temporaries created in the function call expression, and that it would be unsafe to use the returned object after the full expression expires.

fmt/include/fmt/core.h

Lines 1622 to 1623 in b8ff3c1

Returns a named argument to be used in a formatting function. It should only
be used in a call to a formatting function.

That's no longer true as other examples like

fmt/include/fmt/args.h

Lines 180 to 181 in b8ff3c1

auto a1 = fmt::arg("a1_", a1_val);
store.push_back(std::cref(a1));
show the result being retained in auto variables and passed to fmt::dynamic_format_arg_store via push_back.

I want to use dynamic_format_arg_store but it looks like I'm breaking the fmt::arg contract to do it.
I know it's safe, but the docs don't quite match the reality.

Should the "It should only be used in a call to a formatting function" be removed or updated?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions