-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
fmt/printf.h with wchar_t* loses int type #1316
Comments
The problem is that Line 861 in f7aedc5
T is convertible to an integral type (or floating point type for that matter).
|
On a second thought, the current behavior is correct because one should be able to override implicit conversion. To fix the issue either don't include #include <iostream>
#define FMT_HEADER_ONLY 1
#include <fmt/printf.h> // this should really be <fmt/format.h>
#include <boost/date_time/gregorian/gregorian.hpp>
namespace fmt {
template <typename Char>
struct formatter<boost::gregorian::greg_year, Char> : formatter<int, Char> {
template <typename Context>
auto format(boost::gregorian::greg_year y, Context& ctx) {
return formatter<int, Char>::format(y, ctx);
}
};
}
int main() {
boost::gregorian::greg_year year(2015);
std::wcout << fmt::format(L"{:d}", year);
} |
@vitaut: I have same thoughts until I discover that error disappears when I use char* instead of wchar_t*. So
fails, but
not. So I think there are question of consistency. I'am expect that both cases work or both cases fail. Why the problem exists only with wchar_t pointer? |
And second question is why fmt try to deduce argument explicitly requested as int "{:d}" through operator<< even if int type can be inferred. |
Great question. As it turned out there is a difference in standard overload sets for
It's mostly for enums since people may want to override implicit conversion with Should be fixed in ccc8f5d. |
This code works just fine:
https://godbolt.org/z/x2BA0m
But if I include <fmt/printf.h> instead of <format.h> I've got a runtime error:
https://godbolt.org/z/e2x3Sp
With char* formatting there is no error:
https://godbolt.org/z/Z80SwD
The text was updated successfully, but these errors were encountered: