From f1963324d26e825cd4cce3f666702933b86d92c8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 23 Mar 2012 12:25:33 +0100 Subject: QUuid: mark constructors constexpr See e.g. f3141c58badbd2da9eb42 for rationale. The problematic part here is the array member which in C++98 cannot be initialised in the ctor-initializer-list. For this, C++11 Uniform Initialisation is needed, for which Qt does not yet have a Q_COMPILER_* macro. I'm not sure we need one, either, since I doubt that there's a compiler that implements std::initializer_list, but not uniform initialisation. Change-Id: I4fa8f4f9db8703096358634fb2e6f5de61f0fedd Reviewed-by: Denis Dzyubenko Reviewed-by: Thiago Macieira --- src/corelib/plugin/quuid.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h index dee97d93a5..05f44b4c25 100644 --- a/src/corelib/plugin/quuid.h +++ b/src/corelib/plugin/quuid.h @@ -84,6 +84,13 @@ public: Sha1 = 5 // 0 1 0 1 }; +#ifdef Q_COMPILER_INITIALIZER_LISTS // UNIFORM_INITIALIZATION + Q_DECL_CONSTEXPR QUuid() + : data1(0), data2(0), data3(0), data4{0,0,0,0,0,0,0,0} {} + + Q_DECL_CONSTEXPR QUuid(uint l, ushort w1, ushort w2, uchar b1, uchar b2, uchar b3, uchar b4, uchar b5, uchar b6, uchar b7, uchar b8) + : data1(l), data2(w1), data3(w2), data4{b1, b2, b3, b4, b5, b6, b7, b8} {} +#else QUuid() { data1 = 0; @@ -106,6 +113,8 @@ public: data4[6] = b7; data4[7] = b8; } +#endif + #ifndef QT_NO_QUUID_STRING QUuid(const QString &); QUuid(const char *); @@ -142,6 +151,12 @@ public: #if defined(Q_OS_WIN) // On Windows we have a type GUID that is used by the platform API, so we // provide convenience operators to cast from and to this type. +#ifdef Q_COMPILER_INITIALIZER_LISTS // UNIFORM_INITIALIZATION + Q_DECL_CONSTEXPR QUuid(const GUID &guid) + : data1(guid.Data1), data2(guid.Data2), data3(guid.Data3), + data4{guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], + guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]} {} +#else QUuid(const GUID &guid) { data1 = guid.Data1; @@ -150,6 +165,7 @@ public: for(int i = 0; i < 8; i++) data4[i] = guid.Data4[i]; } +#endif QUuid &operator=(const GUID &guid) { -- cgit v1.2.3