How to compile Hinnant short_alloc allocator

I would like to try the new Hinnant short_alloc allocator , which, as I understand it, replaces the old stack_alloc . However, I cannot compile a vector example. g++ says:

 ~# g++ -std=c++11 stack-allocator-test.cpp -o stack-allocator-test In file included from stack-allocator-test.cpp:6:0: short_alloc.h:11:13: error: 'alignment' is not a type short_alloc.h:11:22: error: ISO C++ forbids declaration of 'alignas' with no type [-fpermissive] short_alloc.h:11:22: error: expected ';' at end of member declaration 

As far as I can tell, g++ complains about line 10 and 11 :

 static const std::size_t alignment = 16; alignas(alignment) char buf_[N]; 

It seems that the compiler does not like the "version of the expression" alignas , but it expects only a "version identifier type".

I am using g++ 4.7.2 under Ubuntu 12.10.

 ~# g++ --version g++ (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2 

I guess I'm missing something obvious, but I can't figure it out. Any help would be greatly appreciated. (Please do not tell me that I need to switch to the new g++ , I'm too lazy to do this :)

+4
source share
1 answer

g ++ - 4.7.2 does not support alignas . From http://gcc.gnu.org/projects/cxx0x.html :

Alignment Support | N2341 | Gcc 4.8

Try using g ++ - 4.8.0 or clang; you can also use __attribute__((aligned)) :

 __attribute__((aligned (8))) char buf_[12]; 

Note that __attribute__((aligned)) accepts only certain integer constant expressions (literals, template parameters); it does not accept static const variables.

+7
source

All Articles