Fix build with MSVC 2015 Update 2 if constexpr is enabled

This compiler seems to require explicit initialization of all member
variables in a constexpr constructor, even if they have an implicit
default constructor of their own. We probably fixed the rest of Qt a
couple of years ago, but not these two places because they were arrays
and those require the C++11 syntax for uniform initialization.

All compilers that support constexpr do support uniform initialization.
MSVC 2015 fixed our issues with it on the same update.

Change-Id: Ibc1eb23e3ae093f5c6928ded3a041be35eb9baae
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Thiago Macieira 2017-06-09 14:46:01 -07:00
parent d3590d32a5
commit fb046c932f
2 changed files with 11 additions and 2 deletions

View File

@ -207,7 +207,11 @@ public:
template <typename T, typename ConstantsType>
Q_DECL_CONSTEXPR inline QFreeList<T, ConstantsType>::QFreeList()
: _next(ConstantsType::InitialNextValue)
:
#if defined(Q_COMPILER_CONSTEXPR)
_v{}, // uniform initialization required
#endif
_next(ConstantsType::InitialNextValue)
{ }
template <typename T, typename ConstantsType>

View File

@ -832,7 +832,12 @@ class StaticDayOfWeekAssociativeArray {
static Q_DECL_CONSTEXPR int day2idx(Qt::DayOfWeek day) Q_DECL_NOTHROW { return int(day) - 1; } // alt: day % 7
public:
Q_DECL_CONSTEXPR StaticDayOfWeekAssociativeArray() Q_DECL_NOEXCEPT_EXPR(noexcept(T()))
: contained(), data() {}
#ifdef Q_COMPILER_CONSTEXPR
: contained{}, data{} // arrays require uniform initialization
#else
: contained(), data()
#endif
{}
Q_DECL_CONSTEXPR bool contains(Qt::DayOfWeek day) const Q_DECL_NOTHROW { return contained[day2idx(day)]; }
Q_DECL_CONSTEXPR const T &value(Qt::DayOfWeek day) const Q_DECL_NOTHROW { return data[day2idx(day)]; }