[Issue 18054] Wrong cast of float constant to bool

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Nov 11 11:07:01 UTC 2021


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #2 from Dlang Bot <dlang-bot at dlang.rocks> ---
@MoonlightSentinel created dlang/dmd pull request #13285 "Fix 18054 - Use
toBool instead of toInteger when const-folding cast(b…" fixing this issue:

- Fix 18054 - Use toBool 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.

  Teh 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