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

Documentation: API example for user-defined formatter doesn't compile #3818

Closed
frank-weinberg opened this issue Jan 19, 2024 · 1 comment · Fixed by #3820
Closed

Documentation: API example for user-defined formatter doesn't compile #3818

frank-weinberg opened this issue Jan 19, 2024 · 1 comment · Fixed by #3820

Comments

@frank-weinberg
Copy link
Contributor

The example for defining a custom formatter via specializing the formatterstruct in https://fmt.dev/latest/api.html#formatting-user-defined-types fails to compile when the definition of the format function is in a different compilation unit than its usage.

Using color.h and color.cc as in the API doc and a simple main.cc:

#include "color.h"

int main() { fmt::print("{}\n", color::red); }

gives the error (gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04) ):

 /workspaces/frawen/temp/fmt-10.2.1/include/fmt/core.h:1328:28: error: use of ‘auto fmt::v10::formatter<color>::format(color, fmt::v10::format_context&) const’ before deduction of ‘auto’

After amending the signature of format to

auto format(color c, format_context &ctx) const -> format_context::iterator

in both color.h and color.cc, the code works as expected.

(No godbolt because I couldn't get its multifile mode to work.)

@vitaut
Copy link
Contributor

vitaut commented Jan 19, 2024

Good catch, thanks. Could you by any chance submit a PR with the signature change?

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 a pull request may close this issue.

2 participants