From 8d56623d29163c49442851f5c9a3af1adf2360c8 Mon Sep 17 00:00:00 2001 From: Robin Caloudis Date: Tue, 16 Jul 2024 20:41:02 +0200 Subject: [PATCH] Extract template and leave comment --- .../std/numerics/c.math/isfinite.pass.cpp | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/libcxx/test/std/numerics/c.math/isfinite.pass.cpp b/libcxx/test/std/numerics/c.math/isfinite.pass.cpp index 35a054c5bcd52c..3d5be616343343 100644 --- a/libcxx/test/std/numerics/c.math/isfinite.pass.cpp +++ b/libcxx/test/std/numerics/c.math/isfinite.pass.cpp @@ -62,30 +62,21 @@ 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); } +template +struct ConvertibleTo { + operator T() const { return T(); } }; 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))); + + // Make sure we can call `std::isfinite` with convertible types + { + assert(std::isfinite(ConvertibleTo())); + assert(std::isfinite(ConvertibleTo())); + assert(std::isfinite(ConvertibleTo())); + } return 0; }