summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qendian.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2015-01-14 11:02:28 -0800
committerThiago Macieira <thiago.macieira@intel.com>2015-01-17 05:03:33 +0100
commitec9bc843d8a5c18459f3669c6e22acac2077df67 (patch)
treeacb1c338c965e132832cd63abee22bba5f88d779 /src/corelib/global/qendian.h
parentbe5b04fd3782cc17bebef5ad9ffd302b8a1edef4 (diff)
Fix compilation with Apple Clang 425
This version was based on Clang mainline between releases 3.1 and 3.2, which means it has part of 3.2 features but not all. One of the missing features is __builtin_bswap16. Change-Id: Ic5d393bfd36e48a193fcffff13b95664c7f664de Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'src/corelib/global/qendian.h')
-rw-r--r--src/corelib/global/qendian.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/corelib/global/qendian.h b/src/corelib/global/qendian.h
index 7c643f7592..0e383c18d2 100644
--- a/src/corelib/global/qendian.h
+++ b/src/corelib/global/qendian.h
@@ -272,9 +272,15 @@ template <> inline qint8 qFromBigEndian<qint8>(const uchar *src)
*/
template <typename T> T qbswap(T source);
+#ifdef __has_builtin
+# define QT_HAS_BUILTIN(x) __has_builtin(x)
+#else
+# define QT_HAS_BUILTIN(x) 0
+#endif
+
// GCC 4.3 implemented all the intrinsics, but the 16-bit one only got implemented in 4.8;
// Clang 2.6 implemented the 32- and 64-bit but waited until 3.2 to implement the 16-bit one
-#if (defined(Q_CC_GNU) && Q_CC_GNU >= 403) || (defined(Q_CC_CLANG) && Q_CC_CLANG >= 206)
+#if (defined(Q_CC_GNU) && Q_CC_GNU >= 403) || QT_HAS_BUILTIN(__builtin_bswap32)
template <> inline quint64 qbswap<quint64>(quint64 source)
{
return __builtin_bswap64(source);
@@ -306,7 +312,7 @@ template <> inline quint32 qbswap<quint32>(quint32 source)
| ((source & 0xff000000) >> 24);
}
#endif // GCC & Clang intrinsics
-#if (defined(Q_CC_GNU) && Q_CC_GNU >= 408) || (defined(Q_CC_CLANG) && Q_CC_CLANG >= 302)
+#if (defined(Q_CC_GNU) && Q_CC_GNU >= 408) || QT_HAS_BUILTIN(__builtin_bswap16)
template <> inline quint16 qbswap<quint16>(quint16 source)
{
return __builtin_bswap16(source);
@@ -320,6 +326,8 @@ template <> inline quint16 qbswap<quint16>(quint16 source)
}
#endif // GCC & Clang intrinsics
+#undef QT_HAS_BUILTIN
+
// signed specializations
template <> inline qint64 qbswap<qint64>(qint64 source)
{