summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2019-06-12 01:30:10 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2019-06-12 01:45:52 +0200
commitff88c3bc55acefb3e57c01162d2dc04c5e24a276 (patch)
treef93e59a3aebc4a6d616b6fbddedfe7a08d0f7517 /src/corelib/tools
parent620f12120618ae548575c741a9dc54e405aefed4 (diff)
Q_ARRAY_LITERAL: fix the checks on the payload's datatype
The check was a misnomer -- non-POD types can go in unions since C++11. And we may want them, e.g. types without a trivial default constructor. What we really want is to check for a literal type (so that the array payload can be built entirely at compile time, and put in .rodata). So, amend the check. Also, make the dummy array constexpr, to be sure that we are indeed building the payload using constexpr constructors. That would make the first check redundant, but the fact that we're still using a macro for constexpr makes me think that not all compilers support it, so I'm leaving the first check in... Change-Id: I9f1473aa74dff5b6b6535ae4cd8325451c0b18e6 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qarraydata.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h
index 7e3f8c9dbd..074072b987 100644
--- a/src/corelib/tools/qarraydata.h
+++ b/src/corelib/tools/qarraydata.h
@@ -324,10 +324,10 @@ struct QArrayDataPointerRef
/**/
#define Q_ARRAY_LITERAL_IMPL(Type, ...) \
- union { Type type_must_be_POD; } dummy; Q_UNUSED(dummy) \
+ Q_STATIC_ASSERT(std::is_literal_type<Type>::value); \
\
/* Portable compile-time array size computation */ \
- Type data[] = { __VA_ARGS__ }; Q_UNUSED(data) \
+ Q_CONSTEXPR Type data[] = { __VA_ARGS__ }; Q_UNUSED(data); \
enum { Size = sizeof(data) / sizeof(data[0]) }; \
\
static const QStaticArrayData<Type, Size> literal = { \