From 3a1f9dec7cdc0f6504eed8157f6fcb0a9638c109 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 1 Jul 2019 20:55:46 +0200 Subject: 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 --- tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/auto/corelib') 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 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. -- cgit v1.2.3