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

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

Closed
shi-yan opened this issue Sep 21, 2019 · 1 comment
Closed

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

shi-yan opened this issue Sep 21, 2019 · 1 comment

Comments

@shi-yan
Copy link

shi-yan commented Sep 21, 2019

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)

@sharkdp
Copy link
Owner

sharkdp commented Sep 21, 2019

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.

@sharkdp sharkdp closed this as completed Sep 23, 2019
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