summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlist.h
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-03-15 14:37:41 +0100
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-03-15 21:13:31 +0100
commit9bf056e3f759ef87aca9c1f481ac3fb28e6599b9 (patch)
tree70f6b7110c4bd9ec71fae8e16c03003aabbf2341 /src/corelib/tools/qlist.h
parent835b795c3dd752f11c11178bf52b018ddc76b368 (diff)
fix aliasing issue in node_construct()
invisible so far, but the next patch uncovers it. this could be possibly optimized for more compilers. however, i found no way to ask msvc whether it is doing an optimized build. Reviewed-by: thiago
Diffstat (limited to 'src/corelib/tools/qlist.h')
-rw-r--r--src/corelib/tools/qlist.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index dc8c849e8b..e3b8e1b545 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -377,7 +377,15 @@ Q_INLINE_TEMPLATE void QList<T>::node_construct(Node *n, const T &t)
{
if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) n->v = new T(t);
else if (QTypeInfo<T>::isComplex) new (n) T(t);
+#if (defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__IBMCPP__)) && !defined(__OPTIMIZE__)
+ // This violates pointer aliasing rules, but it is known to be safe (and silent)
+ // in unoptimized GCC builds (-fno-strict-aliasing). The other compilers which
+ // set the same define are assumed to be safe.
else *reinterpret_cast<T*>(n) = t;
+#else
+ // This is always safe, but penaltizes unoptimized builds a lot.
+ else ::memcpy(n, &t, sizeof(T));
+#endif
}
template <typename T>