diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2017-05-05 13:54:06 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2017-05-06 02:57:41 +0000 |
commit | 02700cf6c23f1095a9187230220dd9b97082d61a (patch) | |
tree | 50b3b8fb6061152d78607ded24aff0e36a821aff /src/corelib/global/qglobal.cpp | |
parent | 9e1f60053a7169cc9098cc8823e1daae6d58331c (diff) |
Add an extra check for qssize_t's size and type
The definitions of size_t and ptrdiff_t ([support.types.layout] p2 and
p3 respectively) do not specify that they need to be as big as a
pointer. They just need to be big enough to hold the size of the largest
object and the biggest array subscript, respectively, the platform
supports (e.g., 16-bit DOS would have them as 16-bit in all memory
models, except huge).
But we depend on them actually being the size of a pointer in many
places, such as in QArrayData::offset, that stores the linear distance
from the end of the structure to the beginning of the data, wherever it
is in memory.
It's also a good idea to verify that qptrdiff and qssize_t are the same
type.
Change-Id: I9ad33fff8b634979bdbafffd14bbd1223afc58e8
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/corelib/global/qglobal.cpp')
-rw-r--r-- | src/corelib/global/qglobal.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 150ae7cf49..bb944c4d8e 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -140,6 +140,11 @@ Q_STATIC_ASSERT_X(std::numeric_limits<float>::has_infinity && Q_STATIC_ASSERT_X(std::numeric_limits<float>::radix == 2, "Qt assumes binary IEEE 754 floating point"); +// not required by the definition of size_t, but we depend on this +Q_STATIC_ASSERT_X(sizeof(size_t) == sizeof(void *), "size_t and a pointer don't have the same size"); +Q_STATIC_ASSERT(sizeof(size_t) == sizeof(qssize_t)); // implied by the definition +Q_STATIC_ASSERT((std::is_same<qssize_t, qptrdiff>::value)); + /*! \class QFlag \inmodule QtCore |