[PATCH] D132739: [clang][Interp] Implement IntegralToBoolean casts

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 26 21:56:19 PDT 2022


tbaeder marked an inline comment as done.
tbaeder added inline comments.


================
Comment at: clang/lib/AST/Interp/Boolean.h:90
+  template <typename T> static Boolean from(T Value) {
+    if constexpr (std::is_integral<T>::value)
+      return Boolean(Value != 0);
----------------
shafik wrote:
> This should work for `floating_point` as well.
We don't do floating point values yet.


================
Comment at: clang/lib/AST/Interp/Boolean.h:91
+    if constexpr (std::is_integral<T>::value)
+      return Boolean(Value != 0);
+    return Boolean(static_cast<decltype(Boolean::V)>(Value) != 0);
----------------
shafik wrote:
> Why the `!= 0` shouldn't these all implicitly convert to `bool` with appropriate values?
Not 100% sure why this was used, it was there before so I left it in.


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

https://reviews.llvm.org/D132739



More information about the cfe-commits mailing list