[Bug libstdc++/72792] allocator_traits is too strict about rebinding
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Feb 14 18:30:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72792
--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Liviu Ionescu from comment #6)
> > If you have real world code that is affected ...
>
> I do, it is called µOS++, and it is a C++ RTOS with advanced memory
> management features, using C++17 memory resources and C++11 standard
> allocators:
>
> https://github.com/micro-os-plus/micro-os-plus-iii
>
> It was developed on clang and GCC 5.x. When I tried GCC 6.x, it failed.
> Today I took some time to understand why, and discovered the static assert
> in the allocator_traits<> template.
>
> I removed it and this solved the problem.
>
> Now I'm working on a patch for GCC 6.x distributions, so I can run my tests
> on CI servers until 6.4 will be released.
>
> I'm a bit surprised that there were no other reports, according to my tests
> the bug affected all custom allocators that use pointers to functions or
> pointer to class members as template parameters. (I wrote a simple test,
> trying several types of template parameters).
Only if they don't provide their own "rebind"
If the allocator provides a rebind then it will be used, and there's no need
for the deduction (which fails with non-type template parameters).
The simplest fix would be to add rebind to your allocators:
template<class T, void*(*F)(int)>
struct Alloc
{
using value_type = T;
template<typename U>
struct rebind {
using other = Alloc<U, F>;
};
// ...
};
This will work with any C++11 compiler.
More information about the Gcc-bugs
mailing list