sharkdp/dbg-macro

Unable to print std::string when printing multiple variables.

shi-yan opened this issue · 1 comments

The following fails to print the content of t->message

  struct Test{
    std::string message;
  };

  std::shared_ptr<Test> t(new Test);
  t->message = "hello";
  dbg("Request from", t->message, 23);

expected output:

[..xxx.cpp:24 (helloWorld)] "Request from", t->message = "hello" (std::string), 23 = 23 (int)

actual output:

[..xxx.cpp:24 (helloWorld)] "Request from", t->message, 23 = 23 (int)

Thank you for your report.

This is basically a duplicate of #2 because dbg(…) doesn't currently support multiple arguments. What happens is that

"Request from", t->message, 2

is treated as a comma-operator expression which evaluates to 2. This is why this line (confusingly) prints "Request from", t->message, 23 = 23 (the left-hand side of the = sign is just the stringified expression inside the dbg(…) macro).

This is not related to std::string.