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

LWG 3636 #3447

Closed
ecatmur opened this issue May 17, 2023 · 3 comments
Closed

LWG 3636 #3447

ecatmur opened this issue May 17, 2023 · 3 comments

Comments

@ecatmur
Copy link

ecatmur commented May 17, 2023

Per https://cplusplus.github.io/LWG/issue3636, formatters should have format() const. Failure to enforce this impedes compatibility with standard formatting i.e. once we've written formatters for fmt, we need to go and add const on format() to make them compatible with std::format.

Please consider enforcing that formatter<T>::format() specialization member functions can be called const. Perhaps this could be done with deprecation initially.

@ecatmur
Copy link
Author

ecatmur commented May 17, 2023

#include <fmt/format.h>
#include <format>

struct A {};
template<>
struct fmt::formatter<A> {
    auto format(A, auto& ctx) /* const */ -> decltype(ctx.out());
    constexpr auto parse(auto& ctx) { return ctx.begin(); }
};
template<>
struct std::formatter<A> : fmt::formatter<A> {};

int main() {
    (void) fmt::format("{}", A()); // 1
    (void) std::format("{}", A()); // 2
}

compiles (1) but fails to compile (2). Uncommenting the /* const */ makes both compile. https://godbolt.org/z/jWPGs49Ka

@infdahai
Copy link

maybe just add the const flag to the template.

@vitaut
Copy link
Contributor

vitaut commented Jan 14, 2024

Done in d707292.

@vitaut vitaut closed this as completed Jan 14, 2024
facebook-github-bot pushed a commit to facebookincubator/fizz that referenced this issue Aug 8, 2024
Summary:
starting from [fmt11.0.0](fmtlib/fmt#3447), fmt requires formatter::format to be const.
> Started enforcing that formatter::format is const for compatibility with std::format

Pull Request resolved: #144

Reviewed By: NickR23

Differential Revision: D60912017

Pulled By: mingtaoy

fbshipit-source-id: 49e367c509a84523455220d791402ca4669942bd
facebook-github-bot pushed a commit to facebook/hhvm that referenced this issue Sep 11, 2024
Summary:
starting from [fmt11.0.0](fmtlib/fmt#3447), fmt requires formatter::format to be const.
> Started enforcing that formatter::format is const for compatibility with std::format

X-link: facebookincubator/fizz#144

Reviewed By: NickR23

Differential Revision: D60912017

Pulled By: mingtaoy

fbshipit-source-id: 49e367c509a84523455220d791402ca4669942bd
le-migou added a commit to calculisto/units that referenced this issue Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants