Bug 17639 – Implicit conversion of bool to float should be rejected

Status
REOPENED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-07-12T09:59:25Z
Last change time
2024-12-13T18:53:19Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
drug007
Moved to GitHub: dmd#17805 →

Comments

Comment #0 by drug2004 — 2017-07-12T09:59:25Z
Found by typo, forget to remove `isNaN` and code still compiles giving wrong result: ``` import std.math; int main() { float a = 0, b = 10_000; static assert (!__traits(compiles, q{ // isNaN wasn't removed during copy-paste // but code still compiles with wrong result assert (a.approxEqual(b.isNaN) == false); }), "This code must not compile!"); return 0; } ```
Comment #1 by simen.kjaras — 2017-07-12T10:39:54Z
There's nothing particular about approxEqual in this case - at least 26 out of 70 functions in std.math accept bools for at least one of their parameters. This bug report basically boils down to this code: float f = false; This compiles and is valid D. (and the value of f is 0)
Comment #2 by dlang-bugzilla — 2017-07-15T02:49:13Z
(In reply to Simen Kjaeraas from comment #1) > This bug report basically boils down to this code: > > float f = false; That doesn't make sense and doesn't seem useful, so let's reopen it as an accepts-invalid.
Comment #3 by robert.schadek — 2024-12-13T18:53:19Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17805 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB