-
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
Regression: custom ostream formatting doesn't work with namespaced types after v7 #2130
Comments
I have experienced this issue as well. |
16cac46 is a fix for #1766. Unfortunately I don't know how to make both cases work. Considering that defining namespace ns
{
class test {};
std::ostream& operator<<(std::ostream& Stream, test const&)
{
Stream << "ns::test\n";
return Stream;
}
} If someone knows a solution that doesn't break #1766, a PR would be welcome. |
Clarified the limitation in the docs: d281018. |
Unfortunately that's UB for std types :( |
You can also provide a template <>
struct fmt::formatter<ns::test> : formatter<std::string> {
auto format(const ns::test& t, format_context& ctx) {
std::ostringstream os;
os << t;
return formatter<std::string>::format(os.str(), ctx);
}
}; We could make it simpler, something like: template <> struct fmt::formatter<ns::test> : fmt::ostream_formatter<ns::test> {}; and this won't have the include order problem. |
Thank you - a formatter specialization works as expected. |
Version: latest
operator<<
in global namespace should be discoverable as long as it is defined before fmt facilities.And it worked like that at least until v7 (godbolt).
However, at some point after v7, presumably after 16cac46, it stopped working (godbolt).
The latest trunk works if the offending code is commented (godbolt).
The text was updated successfully, but these errors were encountered: