D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20534 - std.format: %r on boolean gives wrong result
Summary: std.format: %r on boolean gives wrong result
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: berni44
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2020-01-26 12:02 UTC by berni44
Modified: 2021-04-08 13:36 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description berni44 2020-01-26 12:02:17 UTC
The output of %r on booleans gives 4 bytes, not only one, because the bool is cast to an int before it is formatted. This is inconsistent with other uses of %r (which is yet undocumented).

void main()
{
    import std.format : format;

    assert(format("%r",false) == "\0"); // fails
}
Comment 1 Dlang Bot 2021-04-08 11:54:05 UTC
@berni44 created dlang/phobos pull request #7946 "Fix Issue 20534 - std.format: %r on boolean gives wrong result" fixing this issue:

- Fix Issue 20534 - std.format: %r on boolean gives wrong result

https://github.com/dlang/phobos/pull/7946
Comment 2 Dlang Bot 2021-04-08 13:36:12 UTC
dlang/phobos pull request #7946 "Fix Issue 20534 - std.format: %r on boolean gives wrong result" was merged into master:

- f455389d7f2da3d8ab506a6b4345ca956a32158a by berni44:
  Fix Issue 20534 - std.format: %r on boolean gives wrong result

https://github.com/dlang/phobos/pull/7946