c++/10479: __alignof__(double) not compile time constant inside template class

rguenth@tat.physik.uni-tuebingen.de rguenth@tat.physik.uni-tuebingen.de
Thu Apr 24 12:41:00 GMT 2003

>Number:         10479
>Category:       c++
>Synopsis:       __alignof__(double) not compile time constant inside template class
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Thu Apr 24 12:16:01 UTC 2003
>Originator:     Richard Guenther
>Release:        from 2.95 throughout 3.4
ia32 linux-gnu
__alignof__(double) or any other not-dependend type is rejected as being not compile-time constant in a template class. Like:

template <int i>
struct foo2 {
        float bar __attribute__((aligned(__alignof__(double))));

while in a non-template context (just omit the template <int i> from the above example), it is accepted. Also specifying 8 rather than __alignof__(double) is ok.

bellatrix:~/src/tests$ g++ -c attribute.cpp 
attribute.cpp:7: requested alignment is not a constant

While of course __alignof__ is a gnu extension this behavior may be "correct", but it is surely not what one would expect and undocumented.

A workaorund is to use a configure check for the alignment and create a #define for the actual constant.

More information about the Gcc-bugs mailing list