summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2019-07-01 20:55:46 +0200
committerMarc Mutz <marc.mutz@kdab.com>2019-07-06 19:07:04 +0000
commit3a1f9dec7cdc0f6504eed8157f6fcb0a9638c109 (patch)
tree400f62d105ccb3a56bc212a5d12824b61558696d
parenteea99e1e8f3eb67fda35dd3a656fe9b5a9be84f2 (diff)
Q_ARRAY_LITERAL: protect the check for literal types
Some compilers (hello, MSVC) do not produce literal types in Qt because their constexpr support has been blacklisted. Therefore, amend the check for literal types in Q_ARRAY_LITERAL: only do the check if the compiler supports constexpr. Change-Id: I7cffe00dde447d975aa6a7d02248df9c351508ff Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
-rw-r--r--src/corelib/tools/qarraydata.h8
-rw-r--r--tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp12
2 files changed, 19 insertions, 1 deletions
diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h
index 074072b987..dcd95924c1 100644
--- a/src/corelib/tools/qarraydata.h
+++ b/src/corelib/tools/qarraydata.h
@@ -323,8 +323,14 @@ struct QArrayDataPointerRef
}()) \
/**/
+#ifdef Q_COMPILER_CONSTEXPR
+#define Q_ARRAY_LITERAL_CHECK_LITERAL_TYPE(Type) Q_STATIC_ASSERT(std::is_literal_type<Type>::value)
+#else
+#define Q_ARRAY_LITERAL_CHECK_LITERAL_TYPE(Type) do {} while (0)
+#endif
+
#define Q_ARRAY_LITERAL_IMPL(Type, ...) \
- Q_STATIC_ASSERT(std::is_literal_type<Type>::value); \
+ Q_ARRAY_LITERAL_CHECK_LITERAL_TYPE(Type); \
\
/* Portable compile-time array size computation */ \
Q_CONSTEXPR Type data[] = { __VA_ARGS__ }; Q_UNUSED(data); \
diff --git a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
index 7db7d71b1f..25e2f21d03 100644
--- a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
+++ b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
@@ -1625,6 +1625,18 @@ void tst_QArrayData::literals()
QCOMPARE(const_(v)[i], char('A' + i));
QCOMPARE(const_(v)[10], char('\0'));
}
+
+ {
+ struct LiteralType {
+ int value;
+ Q_DECL_CONSTEXPR LiteralType(int v = 0) : value(v) {}
+ };
+
+ QArrayDataPointer<LiteralType> d = Q_ARRAY_LITERAL(LiteralType, LiteralType(0), LiteralType(1), LiteralType(2));
+ QCOMPARE(d->size, 3);
+ for (int i = 0; i < 3; ++i)
+ QCOMPARE(d->data()[i].value, i);
+ }
}
// Variadic Q_ARRAY_LITERAL need to be available in the current configuration.