-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Compile checks in c++20 are kind of lacking #2640
Comments
All of these are expected. It's OK to have unused arguments, named arguments cannot be checked due to C++ limitations and UDL-based API is not recommended at all and will likely be deprecated. |
@vitaut, I'm afraid I have to disagree with you here since only some of them are expected: 1,6 - too many arguments. Unchecked at all - definitely expected, but some strict mode can be helpful, because checking it on the client-side requires excess string parsing pass (for counting)
They cannot be checked for
I don't remember that discouragement of UDL-based usages is stated somewhere. 😏 |
|
Clarified that |
Added a note regarding named arguments to #2390 which already tracks expanding compile-time checks. |
Shouldn't |
Or |
Sure, a PR is welcome =). |
Just curious what was the rationale of deprecating the alternative string literal API? So far I almost exclusively used this API and was surprised to now get deprecation warnings. To me it feels very natural in particular if you are used to |
Mostly because it's inconsistent with all the other formatting functions (and auto operator"" _format(const char* s, size_t n) {
return [=](auto&&... args) {
return fmt::format(fmt::runtime(std::string_view(s, n)), args...);
};
} https://godbolt.org/z/KndTKPe43 This way you'll be able to easily migrate to |
I see. That's a good point you make. I like the option to do a custom wrapper, depending on project needs, which also considers migration to Thanks again to you and all contributors for |
I noticed inline auto operator"" _format(const char* s, size_t n) {
return [=](auto&&... args) {
#if FMT_VERSION < 50000
return fmt::format(s, args...);
#elif FMT_VERSION < 80100
return fmt::format(std::string_view(s, n), args...);
#else
return fmt::format(fmt::runtime(std::string_view(s, n)), args...);
#endif
};
} |
You could also use |
I massively rewrote ostream based logging in my codebase using _format literal. And suddenly I found out that this is not checked at all. I really like the idea of compile-time checked format because it allows seeing all the problems immediately at the compilation stage, instead of waiting for a crash somewhen in future when the code with {fmt} call will be executed. And it's sad that currently it's almost doesn't working.
Here is a list of compile-time checks that works:
https://godbolt.org/z/cc8MPrGc9
Is there a chance that some unchecked scenarios, especially with _format literals would become checked? Now it seems quite inconsistent and confusing.
P.S. I checked only gcc10 and gcc11 with trunk {fmt}. So maybe they don't work only under some list of compilers.
The text was updated successfully, but these errors were encountered: