diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2013-11-12 11:17:05 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-15 06:30:53 +0100 |
commit | 38e90ad2b3cff1220c9214290b4c4fed9dd39bd5 (patch) | |
tree | 1ad6306dae5b5608cdc9b47aef6be29369300c9c | |
parent | 6b8c5ba678a7131c448db656cf62c3f715a2107c (diff) | |
download | qtbase-38e90ad2b3cff1220c9214290b4c4fed9dd39bd5.tar.gz |
qcompilerdetection.h: add Q_COMPILER_UNIFORM_INIT
Up to now, the feature classe Uniform Initialization was subsumed by the
Q_COMPILER_INITIALIZER_LISTS flag together with support for
std::initializer_list.
This caused at least two problems:
1. On QNX, the standard libray does not ship <initializer_list>, even
though the compiler (a GCC 4.6, IIRC) supports it. But since there
was only one Q_COMPILER flag for both, support for the compiler-only
part of the feature had to be disabled, too.
2. MSVC 2013 supports initializer lists, but has a bug that renders full
uniform initialization support, as required for QUuid, useless.
By splitting the feature into two, we can separate them better, and do
so in QUuid, which is the only class that currently takes advantage of
uniform initialization (to provide constexpr constructors).
Since Q_COMPILER_INITIALIZER_LISTS worked as a flag for uniform
initialization so far, with the two known exceptions above,
UNIFORM_INIT is defined whenever INITIALIZER_LIST is, except that
I don't revert UNIFORM_INIT on QNX as I do for INITIALIZER_LISTS
and that I expect the MSVC 2013 features to set INITIALIZER_LIST,
but not UNIFORM_INIT.
Task-number: QTBUG-34705
Change-Id: I81916e950a0f3aab3de7977e0326d2de3d31b14c
Reviewed-by: Yuchen Deng <loaden@gmail.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | doc/global/qt-cpp-defines.qdocconf | 1 | ||||
-rw-r--r-- | src/corelib/global/qcompilerdetection.h | 7 | ||||
-rw-r--r-- | src/corelib/plugin/quuid.h | 4 | ||||
-rw-r--r-- | tests/auto/corelib/plugin/quuid/tst_quuid.cpp | 12 |
4 files changed, 21 insertions, 3 deletions
diff --git a/doc/global/qt-cpp-defines.qdocconf b/doc/global/qt-cpp-defines.qdocconf index b1738e129f..528b0cd561 100644 --- a/doc/global/qt-cpp-defines.qdocconf +++ b/doc/global/qt-cpp-defines.qdocconf @@ -15,6 +15,7 @@ defines += Q_QDOC \ Q_NO_USING_KEYWORD \ __cplusplus \ Q_COMPILER_INITIALIZER_LISTS \ + Q_COMPILER_UNIFORM_INIT \ Q_COMPILER_RVALUE_REFS Cpp.ignoretokens += \ diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index d02e4cf199..f23478d75c 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -465,6 +465,7 @@ * N2659 Q_COMPILER_THREAD_LOCAL * N2765 Q_COMPILER_UDL * N2442 Q_COMPILER_UNICODE_STRINGS + * N2640 Q_COMPILER_UNIFORM_INIT * N2544 Q_COMPILER_UNRESTRICTED_UNIONS * N1653 Q_COMPILER_VARIADIC_MACROS * N2242 N2555 Q_COMPILER_VARIADIC_TEMPLATES @@ -502,6 +503,7 @@ // constexpr support is only partial //# define Q_COMPILER_CONSTEXPR # define Q_COMPILER_INITIALIZER_LISTS +# define Q_COMPILER_UNIFORM_INIT # define Q_COMPILER_NOEXCEPT # endif # if __INTEL_COMPILER >= 1400 @@ -573,6 +575,7 @@ # endif # if __has_feature(cxx_generalized_initializers) # define Q_COMPILER_INITIALIZER_LISTS +# define Q_COMPILER_UNIFORM_INIT /* both covered by this feature macro, according to docs */ # endif # if __has_feature(cxx_lambdas) # define Q_COMPILER_LAMBDA @@ -645,6 +648,7 @@ # define Q_COMPILER_DELETE_MEMBERS # define Q_COMPILER_EXTERN_TEMPLATES # define Q_COMPILER_INITIALIZER_LISTS +# define Q_COMPILER_UNIFORM_INIT # define Q_COMPILER_UNICODE_STRINGS # define Q_COMPILER_VARIADIC_TEMPLATES # endif @@ -718,8 +722,9 @@ # define Q_COMPILER_DECLTYPE # define Q_COMPILER_RVALUE_REFS # define Q_COMPILER_STATIC_ASSERT -// MSVC has std::initilizer_list, but does not support the braces initialization +// MSVC's library has std::initilizer_list, but the compiler does not support the braces initialization //# define Q_COMPILER_INITIALIZER_LISTS +//# define Q_COMPILER_UNIFORM_INIT # endif # if _MSC_VER >= 1700 /* C++11 features supported in VC11 = VC2012: */ diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h index 31b9890351..a0d2923bed 100644 --- a/src/corelib/plugin/quuid.h +++ b/src/corelib/plugin/quuid.h @@ -82,7 +82,7 @@ public: Sha1 = 5 // 0 1 0 1 }; -#if defined(Q_COMPILER_INITIALIZER_LISTS) && !defined(Q_QDOC) +#if defined(Q_COMPILER_UNIFORM_INIT) && !defined(Q_QDOC) 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, @@ -147,7 +147,7 @@ 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. -#if defined(Q_COMPILER_INITIALIZER_LISTS) && !defined(Q_QDOC) +#if defined(Q_COMPILER_UNIFORM_INIT) && !defined(Q_QDOC) 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], diff --git a/tests/auto/corelib/plugin/quuid/tst_quuid.cpp b/tests/auto/corelib/plugin/quuid/tst_quuid.cpp index 197d56359f..227351485d 100644 --- a/tests/auto/corelib/plugin/quuid/tst_quuid.cpp +++ b/tests/auto/corelib/plugin/quuid/tst_quuid.cpp @@ -64,6 +64,7 @@ private slots: void isNull(); void equal(); void notEqual(); + void cpp11(); // Only in Qt > 3.2.x void generate(); @@ -245,6 +246,17 @@ void tst_QUuid::notEqual() QVERIFY( uuidA != uuidB ); } +void tst_QUuid::cpp11() { +#ifdef Q_COMPILER_UNIFORM_INIT + // "{fc69b59e-cc34-4436-a43c-ee95d128b8c5}" cf, initTestCase + Q_DECL_CONSTEXPR QUuid u1{0xfc69b59e, 0xcc34, 0x4436, 0xa4, 0x3c, 0xee, 0x95, 0xd1, 0x28, 0xb8, 0xc5}; + Q_DECL_CONSTEXPR QUuid u2 = {0xfc69b59e, 0xcc34, 0x4436, 0xa4, 0x3c, 0xee, 0x95, 0xd1, 0x28, 0xb8, 0xc5}; + Q_UNUSED(u1); + Q_UNUSED(u2); +#else + QSKIP("This compiler is not in C++11 mode or it doesn't support uniform initialization"); +#endif +} void tst_QUuid::generate() { |