Skip to content

Commit

Permalink
Cast away -Wclass-memaccess warnings in QVarLengthArray methods
Browse files Browse the repository at this point in the history
With g++ 8.2.0, I get warnings when a QVarLengthArray<QString> calls
remove() or prepend(), as some tests in tst_QVarLengthArray do, as
they call memmove() "writing to an object of type ‘class QString’ with
no trivial copy-assignment; use copy-assignment or copy-initialization
instead"; which may indeed be a good argument for not using
QVarLengthArray<QString>, but its own tests do.

Change-Id: I4f8a64948b32a54e67a285df4ec7788f60739ffb
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
ediosyncratic committed Aug 20, 2018
1 parent 54d0621 commit 4932cef
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/corelib/tools/qvarlengtharray.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ Q_OUTOFLINE_TEMPLATE typename QVarLengthArray<T, Prealloc>::iterator QVarLengthA
}
} else {
T *b = ptr + offset;
memmove(b + 1, b, (s - offset) * sizeof(T));
memmove(static_cast<void *>(b + 1), static_cast<const void *>(b), (s - offset) * sizeof(T));
new (b) T(std::move(t));
}
s += 1;
Expand Down Expand Up @@ -518,7 +518,7 @@ Q_OUTOFLINE_TEMPLATE typename QVarLengthArray<T, Prealloc>::iterator QVarLengthA
} else {
T *b = ptr + offset;
T *i = b + n;
memmove(i, b, (s - offset - n) * sizeof(T));
memmove(static_cast<void *>(i), static_cast<const void *>(b), (s - offset - n) * sizeof(T));
while (i != b)
new (--i) T(copy);
}
Expand All @@ -544,7 +544,7 @@ Q_OUTOFLINE_TEMPLATE typename QVarLengthArray<T, Prealloc>::iterator QVarLengthA
i->~T();
}
} else {
memmove(ptr + f, ptr + l, (s - l) * sizeof(T));
memmove(static_cast<void *>(ptr + f), static_cast<const void *>(ptr + l), (s - l) * sizeof(T));
}
s -= n;
return ptr + f;
Expand Down

0 comments on commit 4932cef

Please sign in to comment.