[Development] cast ... increases required alignment of target type [-Werror=cast-align]

Thiago Macieira thiago.macieira at intel.com
Wed Mar 7 09:04:46 CET 2012


On quarta-feira, 7 de março de 2012 09.34.35, Rohan McGovern wrote:
> Does anyone have a suggestion on how to fix this warning?
> 
> This code in qlist.h:
> 
>   409: template <typename T>
>   410: Q_INLINE_TEMPLATE void QList<T>::node_destruct(Node *from, Node *to)
>   411: {
>   412:    if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic)
>   413:        while(from != to) --to, delete reinterpret_cast<T*>(to->v);
>   414:    else if (QTypeInfo<T>::isComplex)
>   415:        while (from != to) --to, reinterpret_cast<T*>(to)->~T();
>   416: }

> src/corelib/tools/qlist.h:415:28: error: cast from
> ‘QList<QVariant>::Node*’ to ‘QVariant*’ increases required alignment of
> target type [-Werror=cast-align]

QList<QVariant>::Node is {
    void *v;
}; (sizeof == 4, alignof == 4)

QVariant is {
    struct Private {
        union Data {
            // among other things
            qlonglong ll;
            qulonglong ull;
            double d;
        };
        uint type;
    } d;
} (sizeof == 12, alignof == 8)

There is an increased alignment requirement in there. However, the side of the 
branch being considered, line 415, is never executed because isLarge == true. 
So this warning is a false positive on a line that gets never compiled.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
     Intel Sweden AB - Registration Number: 556189-6027
     Knarrarnäsgatan 15, 164 40 Kista, Stockholm, Sweden
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20120307/86049b0c/attachment.sig>


More information about the Development mailing list