Bug 16105 – `is` fails for init value of struct with float

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-05-31T09:46:00Z
Last change time
2016-08-19T21:48:02Z
Assigned to
nobody
Creator
schuetzm

Comments

Comment #0 by schuetzm — 2016-05-31T09:46:44Z
The following test case only prints "B: works", although the first comparison should succeed, too: import std.stdio; struct Foo { int x; float f; } void main() { Foo foo; if(foo is Foo.init) "A: doesn't work".writeln; foo = Foo(); if(foo is Foo.init) "B: works".writeln; } Found by ArturG: https://forum.dlang.org/post/[email protected]
Comment #1 by schuetzm — 2016-05-31T09:47:34Z
Addendum: It works correctly with LDC, so it's probably a codegen bug.
Comment #2 by clugdbug — 2016-05-31T12:05:57Z
This isn't a codegen bug per se, but is rather a design bug. It happens because float.init is a signalling NaN. We should change it to be a quiet NaN. Using signalling NaNs seemed like a good idea at the time but it turns out that the hardware support for it just isn't good enough. Even on x86, Intel and AMD CPUs behave differently. And on other CPUs it is even worse. The situation at present is, the intended behaviour is a bit broken on some platforms, and totally broken on others. It is impossible to fix it. It is entirely my fault. When Walter released the backend I did this signalling NaN experiment that I had always wanted to do. I think it was my first compiler patch ever. It was a mistake. A failed experiment. We need to roll it back.
Comment #3 by cauterite — 2016-08-19T21:48:02Z
*** This issue has been marked as a duplicate of issue 15316 ***