[Issue 18054] Wrong cast of float constant to bool

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Nov 12 01:47:57 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=18054

Dlang Bot <dlang-bot at dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #3 from Dlang Bot <dlang-bot at dlang.rocks> ---
dlang/dmd pull request #13285 "Fix 18054 - Use isBool instead of toInteger when
const-folding cast(bool)" was merged into stable:

- ddc6ff08631e221db1b83eca1a07c3d98e4cc9a9 by MoonlightSentinel:
  Fix 18054 - Use isBool instead of toInteger when const-folding cast(bool)

  `RealExp` / `ComplexExp` may hold values that don't have a matching
  integer value (unlike `IntegerExp`). Switching to `toBool` ensures
  proper boolean conversion according to the current type.

  The test output shown below (before this change) was caused by the
  invalid const-folding for floating point literals.

  ```
  float: 1 == 0
  double: 1 == 0
  real: 1 == 0
  ifloat: 1 == 0
  idouble: 1 == 0
  ireal: 1 == 0
  cfloat: 1 == 0
  cdouble: 1 == 0
  creal: 1 == 0
  ```

https://github.com/dlang/dmd/pull/13285

--


More information about the Digitalmars-d-bugs mailing list