[libcxx-commits] [libcxx] [libc++] Fix acceptance of convertible-to-{float, double, long double} in std::isfinite() (PR #98841)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jul 16 07:23:03 PDT 2024


================
@@ -62,9 +62,30 @@ struct TestInt {
   }
 };
 
+struct ConvertibleFloat {
+  int value;
+  ConvertibleFloat(int v) : value(v) {}
+  operator float() const { return static_cast<float>(value); }
+};
+
+struct ConvertibleDouble {
+  int value;
+  ConvertibleDouble(int v) : value(v) {}
+  operator double() const { return static_cast<double>(value); }
+};
+
+struct ConvertibleLongDouble {
+  int value;
+  ConvertibleLongDouble(int v) : value(v) {}
+  operator long double() const { return static_cast<long double>(value); }
+};
+
 int main(int, char**) {
   types::for_each(types::floating_point_types(), TestFloat());
   types::for_each(types::integral_types(), TestInt());
+  assert(std::isfinite(ConvertibleFloat(0)));
+  assert(std::isfinite(ConvertibleDouble(0)));
+  assert(std::isfinite(ConvertibleLongDouble(0)));
----------------
ldionne wrote:

```suggestion
  // Make sure we can call `std::isfinite` with convertible-to-XXX types
  {
    assert(std::isfinite(ConvertibleFloat(0)));
    assert(std::isfinite(ConvertibleDouble(0)));
    assert(std::isfinite(ConvertibleLongDouble(0)));
  }
```

https://github.com/llvm/llvm-project/pull/98841


More information about the libcxx-commits mailing list