-
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
user types + operator<< fails if there's also an operator bool() #1766
Comments
Should be fixed in 16cac46, thanks for reporting. |
Thanks! And once again, thanks for such a great package, all my projects depend on this heavily. |
Hi, was there a reason that this fix was not included in 7.0.2? |
It's a more significant change and will be included in the next minor, not patch release. |
ok, thanks |
This change also fixed the following issue that I had: When I added the following code to static_assert(fmt::detail::type_constant<decltype(fmt::detail::arg_mapper<fmt::buffer_context<char>>().map(std::declval<const unstreamable_enum&>())),
typename fmt::buffer_context<char>::char_type>::value == fmt::detail::type::uint_type, "wrong arg type");
static_assert(fmt::detail::type_constant<decltype(fmt::detail::arg_mapper<fmt::buffer_context<wchar_t>>().map(std::declval<const unstreamable_enum&>())),
typename fmt::buffer_context<wchar_t>::char_type>::value == fmt::detail::type::uint_type, "wrong arg type"); I.e., For me this led to a segfault at runtime, because the argument was of type This was kind of hard to analyze, because I wasn't even using the |
I had a user type (let's call it Type) that defined an
operator<<
.The magic of ostream.h caused this to work as expected for both new format and old sprintf style formatting:
through 6.1.2. But starting with 6.2+, it would render the Type as "true" or "false."
Aha, it turns out that this is because my Type also has an
operator bool()
which fmt was seeming to use to infer printing it as a bool, rather than falling back to theoperator<<
. (For <= 6.1.2, the operator bool() didn't confuse it, it always used the operator<< as expected.)I tried defining a
template <> struct fmt::formatter<Type>
, the preferred method when not usingoperator<<
. And this works... for fmt::format(), but does not seem to help printf/sprintf in any way, where %s still is confused and renders the type as if it were a bool.The text was updated successfully, but these errors were encountered: