Bug 56019

Summary: max_align_t should be in std namespace
Product: gcc Reporter: Matthias Kretz (Vir) <mkretz>
Component: libstdc++Assignee: Paolo Carlini <paolo.carlini>
Status: RESOLVED FIXED    
Severity: normal CC: ai.azuma
Priority: P3 Keywords: rejects-valid
Version: 4.8.0   
Target Milestone: 4.9.0   
Host: Target:
Build: Known to work:
Known to fail: 4.7.2, 4.8.0 Last reconfirmed: 2013-01-17 00:00:00

Description Matthias Kretz (Vir) 2013-01-17 12:58:53 UTC
According to 3.11.2 in the C++11 standard max_align_t should be inside the std namespace (i.e. the text talks about use of alignof(std::max_align_t)). GCC only provides ::max_align_t, though:

% cat main.cpp                                                                                                                                                                                                                  #include <cstddef>
int main()
{
    return alignof(std::max_align_t);
}

% /opt/gcc-4.7.2/bin/g++ -Wall -std=c++11 -o test main.cpp
main.cpp: In function ‘int main()’:
main.cpp:4:20: error: ‘max_align_t’ is not a member of ‘std’
main.cpp:4:20: note: suggested alternative:
In file included from /home/.opt/gcc-4.7.2/bin/../lib/gcc/x86_64-suse-linux-gnu/4.7.2/../../../../include/c++/4.7.2/cstddef:44:0,
                 from main.cpp:1:
/home/.opt/gcc-4.7.2/bin/../lib/gcc/x86_64-suse-linux-gnu/4.7.2/include/stddef.h:426:3: note:   ‘max_align_t’

% /opt/gcc-4.8-snapshot/bin/g++ -Wall -std=c++11 -o test main.cpp
main.cpp: In function ‘int main()’:
main.cpp:4:20: error: ‘max_align_t’ is not a member of ‘std’
     return alignof(std::max_align_t);
                    ^
main.cpp:4:20: note: suggested alternative:
In file included from /home/.opt/gcc-4.8-snapshot/include/c++/4.8.0/cstddef:44:0,
                 from main.cpp:1:
/home/.opt/gcc-4.8-snapshot/lib/gcc/x86_64-suse-linux-gnu/4.8.0/include/stddef.h:425:3: note:   ‘max_align_t’
 } max_align_t;
   ^
Comment 1 Jonathan Wakely 2013-01-17 14:52:45 UTC
<cstddef> just hasn't been updated since max_align_t was added to <stddef.h>
Comment 2 Paolo Carlini 2013-06-11 09:17:06 UTC
Mine.
Comment 3 Paolo Carlini 2013-06-11 09:54:34 UTC
Fixed for 4.9.0. If somebody is interested in 4.8.x too, backporting the patch should not be a big deal.
Comment 4 Jobst.Ziebell 2014-04-22 21:28:33 UTC
The fix introduces another problem. Whenever '__need_size_t' is defined prior to the inclusion of <cstddef>, the type 'max_align_t' will not have been defined.
This inevitably causes a compiler error:

#define __need_size_t
#include <cstddef>

int main( void )
{
    return 0;
}

This happens on Mac OS X 10.9. In my case it got triggered by including <gmp.h>.
Presumably this bug also occurs when #defining the other '__need_*' macros.
Comment 5 Jobst.Ziebell 2014-04-22 21:48:23 UTC
I would propose adding something like

#ifdef _GCC_MAX_ALIGN_T
...
#endif
around the 'using' declaration.

(Though I really have no idea whatsoever off gcc internals...)
Comment 6 Jonathan Wakely 2014-04-23 13:03:32 UTC
(In reply to Jobst.Ziebell from comment #4)
> Presumably this bug also occurs when #defining the other '__need_*' macros.

Which user code should never be doing anyway.

GMP is broken (and already fixed upstream).

This is documented at http://gcc.gnu.org/gcc-4.9/porting_to.html and isn't going to be changed to accomodate broken libraries.