diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2010-03-15 13:37:41 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2010-03-15 20:13:31 (GMT) |
commit | 9bf056e3f759ef87aca9c1f481ac3fb28e6599b9 (patch) | |
tree | 70f6b7110c4bd9ec71fae8e16c03003aabbf2341 /src/corelib | |
parent | 835b795c3dd752f11c11178bf52b018ddc76b368 (diff) | |
download | Qt-9bf056e3f759ef87aca9c1f481ac3fb28e6599b9.zip Qt-9bf056e3f759ef87aca9c1f481ac3fb28e6599b9.tar.gz Qt-9bf056e3f759ef87aca9c1f481ac3fb28e6599b9.tar.bz2 |
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')
-rw-r--r-- | src/corelib/tools/qlist.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index dc8c849..e3b8e1b 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> |