[Issue 22873] New: Wrong std.format output for `inout`
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Mar 11 17:03:44 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=22873
Issue ID: 22873
Summary: Wrong std.format output for `inout`
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: major
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: johanengelen at weka.io
For us, this is a regression since dlang2.099, but the testcase shows the
bigger problem that has apparently always existed.
Testcase:
```
import std.stdio;
import std.format;
struct U8 { string toString() const { return "blah"; } }
struct ContainsU8 {
U8 text;
auto makeInout() inout // with/without `inout` gives different output
{
foo(text);
}
}
void foo(T)(T obj)
{
pragma(msg, T);
writeln(format("%s", obj));
}
void main() {
ContainsU8 a;
a.makeInout();
}
```
This prints "inout(U8)()". If you remove `inout` from line 8, the program
outputs "blah", as it should.
The problem is that `std.format.internal.write.hasToString` does not give
correct output for `inout(T)`, i.e. `hasToString(inout(U8), char)` will return
`HasToStringResult.none`.
Another viewpoint could be that `inout` should not have been applied to the
type of `text` on line 10...
--
More information about the Digitalmars-d-bugs
mailing list