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

user-defined types that have overloaded operator<< #855

Closed
jzablot opened this issue Sep 11, 2018 · 1 comment
Closed

user-defined types that have overloaded operator<< #855

jzablot opened this issue Sep 11, 2018 · 1 comment

Comments

@jzablot
Copy link

jzablot commented Sep 11, 2018

Hi; I'm hitting an issue where user-defined types which overload operator<< are causing seemingly wrongly formatted output if using format_to_n. fmt::format seems to work okay.

Here's an example; I tried against fmtlib 5.1.0 (seems to behave similarly for older versions). I'm building with Visual Studio 2015 on windows, but I think I might be seeing similar behaviour with Xcode (I can confirm if needed).

#include "stdafx.h"

#define FMT_HEADER_ONLY 1
#include <fmt/format.h>
#include <fmt/ostream.h> 


class Test
{
public:

   friend std::ostream& operator<<(std::ostream& strm, const Test& cpstr)
   {
      return strm << "555";
   }
};
 

int main()
{   
   Test a;

   char buf[256];
   fmt::format_to_n_result<char*> res = fmt::format_to_n(buf, 256, "Test {} end", a);
   // buf contains Test  end

   std::string s = fmt::format("Test {} end", a);
   s = s;
   // s contains  Test 555 end   
}

If I switch to use the other style (struct formatter per docs), things start working. But that's not ideal for me since I already have a bunch of classes with stream operators overridden already in various bits of my project.

@vitaut
Copy link
Contributor

vitaut commented Sep 12, 2018

This was fixed in #806.

@vitaut vitaut closed this as completed Sep 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants