[libcxx-commits] [PATCH] D66836: [libc++] Add `__truncating_cast` for safely casting float types to integers

Steve Canon via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 28 12:41:14 PDT 2019


scanon requested changes to this revision.
scanon added inline comments.
This revision now requires changes to proceed.


================
Comment at: include/math.h:1586
+    return _Lim::min();
+  }
+  return static_cast<_IntT>(__trunc_r);
----------------
EricWF wrote:
> scanon wrote:
> > If I'm reading right, NaNs will fall through the above two comparisons and invoke UB on the static_cast below. I suspect that's not the desired behavior. What is the intended result for NaN?
> I didn't want to treat `NaN` as a valid input, so I want to allow UBSAN to catch it rather than to provide a valid output.
Please document this clearly; otherwise someone will assume that this is a UB-free conversion and use it for that purpose.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66836/new/

https://reviews.llvm.org/D66836





More information about the libcxx-commits mailing list