summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2023-12-19 17:40:28 +0100
committerIvan Solovev <ivan.solovev@qt.io>2024-01-19 13:58:57 +0100
commitcfc385ce3fc674d48ea2bfbaac6d3f907795b1a5 (patch)
treec2ce61bd65cd4a6244e5c2492ad15bec0fd94099 /tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp
parent1353c6f85757ad9d9f77bc754bf16c7fb185df00 (diff)
qfloat16: make relational operators constexpr when QFLOAT16_IS_NATIVE
When qfloat16 uses float as an underlying type, the operators cannot be constexpr, because operator float() is not constexpr. However, operator NativeType() is, so we can make the relational operators constexpr when we are using a native 16-bit float as an underlying type. To avoid code duplication, introduce new temporary macros for constexpr and Q_DECLARE_PARTIALLY_ORDERED_LITERAL_TYPE. Extend the tests to verify that the operators are constexpr when native float16 type is used. Task-number: QTBUG-119433 Pick-to: 6.7 Change-Id: I001b087d78c398c71b71a504b65c316199dd4792 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp')
-rw-r--r--tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp
index ddd2058558..477ce90d9f 100644
--- a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp
+++ b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp
@@ -21,6 +21,7 @@ class tst_qfloat16: public QObject
private slots:
void compareCompiles();
+ void relationalOperatorsAreConstexpr();
void ordering_data();
void ordering();
void fuzzyCompare_data();
@@ -80,6 +81,45 @@ void tst_qfloat16::compareCompiles()
#endif
}
+void tst_qfloat16::relationalOperatorsAreConstexpr()
+{
+#if QFLOAT16_IS_NATIVE
+
+#define CHECK_CONSTEXPR(Type) \
+ do { \
+ constexpr qfloat16 lhs = qfloat16(0.0f); \
+ constexpr Type rhs = 1; \
+ static_assert(lhs < rhs); \
+ static_assert(rhs >= lhs); \
+ } while (false)
+
+ CHECK_CONSTEXPR(qfloat16);
+ CHECK_CONSTEXPR(float);
+ CHECK_CONSTEXPR(double);
+ CHECK_CONSTEXPR(long double);
+ CHECK_CONSTEXPR(qfloat16::NativeType);
+ CHECK_CONSTEXPR(qint8);
+ CHECK_CONSTEXPR(quint8);
+ CHECK_CONSTEXPR(qint16);
+ CHECK_CONSTEXPR(quint16);
+ CHECK_CONSTEXPR(qint32);
+ CHECK_CONSTEXPR(quint32);
+ CHECK_CONSTEXPR(long);
+ CHECK_CONSTEXPR(unsigned long);
+ CHECK_CONSTEXPR(qint64);
+ CHECK_CONSTEXPR(quint64);
+#ifdef QT_SUPPORTS_INT128
+ CHECK_CONSTEXPR(qint128);
+ CHECK_CONSTEXPR(quint128);
+#endif
+
+#undef CHECK_CONSTEXPR
+
+#else
+ QSKIP("This check is only relevant for native float16 types");
+#endif // QFLOAT16_IS_NATIVE
+}
+
void tst_qfloat16::ordering_data()
{
QTest::addColumn<float>("left");