Em segunda-feira, 17 de abril de 2017, às 09:48:26 PDT, Marc Mutz escreveu:
> On Monday 17 April 2017 18:08:20 Thiago Macieira wrote:
> > Em segunda-feira, 17 de abril de 2017, às 00:30:23 PDT, Marc Mutz
escreveu:
> > > The problem with QT_STRICT_ITERATORS is _not_ that they are changing
> > > begin() and end(),
> >
> > Actually, it was. You can't use QT_STRICT_ITERATORS in one TU and not in
> > other, regardless of exporting or not.
>
> Why?
Well, now it can, because of this:
iterator begin(iterator = iterator()) Q_DECL_NOTHROW { return data(); }
iterator end(iterator = iterator()) Q_DECL_NOTHROW { return data() + size; }
Because of the parameter, the non-strict version calls begin(T*), whereas the
strict one calls begin(QTypedArrayData<T>::iterator). Those are two different
functions, with different name manglings. When they are emitted out-of-line
and merged at link time, you'll have two copies, not one.
The difference is how the ABI returns the return value: a
QTypedArrayData<T>::iterator is returned by implicit reference, whereas a
pointer is returned by value. In the former case, the caller passes an
implicit parameter to the storage area for the called function. In the latter,
there is no parameter. So if the two functions had the same parameters (and
thus the same mangling), the caller of the non-strict would not pass anything
for the first parameter, causing the called strict begin() function to
dereference an uninitialised pointer.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development