Skip to content

Commit 342bb5b

Browse files
Do a static_cast in bit-blasts that are UB
Without this, building Qt and Qt applications fails with GCC 8. The errors look like this: writing to an object of type ‘class QPointer<QQuickPointerHandler>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Werror=class-memaccess] Task-number: QTBUG-65691 Change-Id: Ie5a30814125deca7a160b9a61f5aa3f944ee1ac9 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
1 parent a87b549 commit 342bb5b

4 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/gui/painting/qmatrix.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ class Q_GUI_EXPORT QMatrix // 2D transform matrix
6565
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
6666
// ### Qt 6: remove; the compiler-generated ones are fine!
6767
QMatrix &operator=(QMatrix &&other) Q_DECL_NOTHROW // = default
68-
{ memcpy(this, &other, sizeof(QMatrix)); return *this; }
68+
{ memcpy(static_cast<void *>(this), static_cast<void *>(&other), sizeof(QMatrix)); return *this; }
6969
QMatrix &operator=(const QMatrix &) Q_DECL_NOTHROW; // = default
7070
QMatrix(QMatrix &&other) Q_DECL_NOTHROW // = default
71-
{ memcpy(this, &other, sizeof(QMatrix)); }
71+
{ memcpy(static_cast<void *>(this), static_cast<void *>(&other), sizeof(QMatrix)); }
7272
QMatrix(const QMatrix &other) Q_DECL_NOTHROW; // = default
7373
#endif
7474

src/gui/painting/qtransform.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ class Q_GUI_EXPORT QTransform
7878
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
7979
// ### Qt 6: remove; the compiler-generated ones are fine!
8080
QTransform &operator=(QTransform &&other) Q_DECL_NOTHROW // = default
81-
{ memcpy(this, &other, sizeof(QTransform)); return *this; }
81+
{ memcpy(static_cast<void *>(this), static_cast<void *>(&other), sizeof(QTransform)); return *this; }
8282
QTransform &operator=(const QTransform &) Q_DECL_NOTHROW; // = default
8383
QTransform(QTransform &&other) Q_DECL_NOTHROW // = default
8484
: affine(Qt::Uninitialized)
85-
{ memcpy(this, &other, sizeof(QTransform)); }
85+
{ memcpy(static_cast<void *>(this), static_cast<void *>(&other), sizeof(QTransform)); }
8686
QTransform(const QTransform &other) Q_DECL_NOTHROW // = default
8787
: affine(Qt::Uninitialized)
88-
{ memcpy(this, &other, sizeof(QTransform)); }
88+
{ memcpy(static_cast<void *>(this), static_cast<const void *>(&other), sizeof(QTransform)); }
8989
#endif
9090

9191
bool isAffine() const;

src/gui/text/qtextengine_p.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,13 @@ struct QGlyphLayout
236236
last = numGlyphs;
237237
if (first == 0 && last == numGlyphs
238238
&& reinterpret_cast<char *>(offsets + numGlyphs) == reinterpret_cast<char *>(glyphs)) {
239-
memset(offsets, 0, (numGlyphs * SpaceNeeded));
239+
memset(static_cast<void *>(offsets), 0, (numGlyphs * SpaceNeeded));
240240
} else {
241241
const int num = last - first;
242-
memset(offsets + first, 0, num * sizeof(QFixedPoint));
242+
memset(static_cast<void *>(offsets + first), 0, num * sizeof(QFixedPoint));
243243
memset(glyphs + first, 0, num * sizeof(glyph_t));
244-
memset(advances + first, 0, num * sizeof(QFixed));
245-
memset(justifications + first, 0, num * sizeof(QGlyphJustification));
244+
memset(static_cast<void *>(advances + first), 0, num * sizeof(QFixed));
245+
memset(static_cast<void *>(justifications + first), 0, num * sizeof(QGlyphJustification));
246246
memset(attributes + first, 0, num * sizeof(QGlyphAttributes));
247247
}
248248
}

src/gui/text/qtextobject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ class Q_GUI_EXPORT QTextFrame : public QTextObject
154154
iterator(const iterator &o) Q_DECL_NOTHROW; // = default
155155
iterator &operator=(const iterator &o) Q_DECL_NOTHROW; // = default
156156
iterator(iterator &&other) Q_DECL_NOTHROW // = default
157-
{ memcpy(this, &other, sizeof(iterator)); }
157+
{ memcpy(static_cast<void *>(this), static_cast<void *>(&other), sizeof(iterator)); }
158158
iterator &operator=(iterator &&other) Q_DECL_NOTHROW // = default
159-
{ memcpy(this, &other, sizeof(iterator)); return *this; }
159+
{ memcpy(static_cast<void *>(this), static_cast<void *>(&other), sizeof(iterator)); return *this; }
160160
#endif
161161

162162
QTextFrame *parentFrame() const { return f; }

0 commit comments

Comments
 (0)