From 4edaeb508132a38aaac2484facca630fa36fbd55 Mon Sep 17 00:00:00 2001 From: Robin Caloudis Date: Mon, 15 Jul 2024 22:05:20 +0200 Subject: [PATCH] Test convertibles in std::isnan() --- .../test/std/numerics/c.math/isnan.pass.cpp | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libcxx/test/std/numerics/c.math/isnan.pass.cpp b/libcxx/test/std/numerics/c.math/isnan.pass.cpp index fffb1246458629..374aa08a600d60 100644 --- a/libcxx/test/std/numerics/c.math/isnan.pass.cpp +++ b/libcxx/test/std/numerics/c.math/isnan.pass.cpp @@ -62,9 +62,30 @@ struct TestInt { } }; +struct ConvertibleFloat { + int value; + ConvertibleFloat(int v) : value(v) {} + operator float() const { return static_cast(value); } +}; + +struct ConvertibleDouble { + int value; + ConvertibleDouble(int v) : value(v) {} + operator double() const { return static_cast(value); } +}; + +struct ConvertibleLongDouble { + int value; + ConvertibleLongDouble(int v) : value(v) {} + operator long double() const { return static_cast(value); } +}; + int main(int, char**) { types::for_each(types::floating_point_types(), TestFloat()); types::for_each(types::integral_types(), TestInt()); + assert(!std::isnan(ConvertibleFloat(0))); + assert(!std::isnan(ConvertibleDouble(0))); + assert(!std::isnan(ConvertibleLongDouble(0))); return 0; }