Silence clang warning in QVector::reallocData()
authorKent Hansen <kent.hansen@nokia.com>
Tue, 19 Jun 2012 08:46:05 +0000 (10:46 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 2 Jul 2012 23:55:42 +0000 (01:55 +0200)
qvector.h:459:30: warning: destination for this 'memcpy' call is a
pointer to dynamic class 'QImage';
vtable pointer will be overwritten [-Wdynamic-class-memaccess]
          ::memcpy(dst, srcBegin, (srcEnd - srcBegin) * sizeof(T));
          ~~~~~~~~ ^
qvector.h:459:30: note: explicitly cast the pointer to silence
this warning
          ::memcpy(dst, srcBegin, (srcEnd - srcBegin) * sizeof(T));
                   ^
                   (void*)

QImage inherits from QPaintDevice, which has virtual functions.
qimage.h declares QImage as a movable type, so
QTypeInfo<QImage>::isStatic is false. Hence, the memcpy codepath will
be reached when the vector is not shared.

We should trust that people declaring such type traits know what
they're doing, so silence the warning.

Change-Id: If36582f57a398fc237fb4bd4f72938fb09667118
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
src/corelib/tools/qvector.h

index b75c297..f3ef9b9 100644 (file)
@@ -456,7 +456,7 @@ void QVector<T>::reallocData(const int asize, const int aalloc, QArrayData::Allo
                         new (dst++) T(*srcBegin++);
                     }
                 } else {
-                    ::memcpy(dst, srcBegin, (srcEnd - srcBegin) * sizeof(T));
+                    ::memcpy(static_cast<void *>(dst), srcBegin, (srcEnd - srcBegin) * sizeof(T));
                     dst += srcEnd - srcBegin;
 
                     // destruct unused / not moved data