From ff88c3bc55acefb3e57c01162d2dc04c5e24a276 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Wed, 12 Jun 2019 01:30:10 +0200 Subject: 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 --- src/corelib/tools/qarraydata.h | 4 ++-- 1 file 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::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 literal = { \ -- cgit v1.2.3