Issue 170761
Summary Non-portable test for allocator_traits::rebind_traits
Labels new issue
Assignees
Reporter jwakely
    https://github.com/llvm/llvm-project/blob/27c4520dc25747703567d68d3704c9b9cc644163/libcxx/test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp#L31

The Cpp17Allocator requirements have a requirement that `allocator_traits<A>::rebind_alloc<A::value_type>` is `A`, i.e. rebinding an allocator to its own value type is a no-op.

Libstdc++ enforces that with a static_assert in `allocator_traits::rebind_alloc`, so this test fails to compile:

```
# | In file included from /home/jwakely/gcc/16/include/c++/16.0.0/ext/alloc_traits.h:36,
# |                  from /home/jwakely/gcc/16/include/c++/16.0.0/bits/stl_uninitialized.h:69,
# |                  from /home/jwakely/gcc/16/include/c++/16.0.0/memory:71,
# |                  from /home/jwakely/src/llvm/llvm-project/libcxx/test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp:18:
# | /home/jwakely/gcc/16/include/c++/16.0.0/bits/alloc_traits.h: In instantiation of ‘struct std::__allocator_traits_base::__rebind<A<char>, double>’:
# | required by substitution of ‘template<class _Alloc> template<class _Tp> using std::allocator_traits< <template-parameter-1-1> >::rebind_traits = std::allocator_traits<typename std::__allocator_traits_base::__rebind<_Alloc, _Tp>::type> [with _Tp = double; _Alloc = A<char>]’
# | /home/jwakely/gcc/16/include/c++/16.0.0/bits/alloc_traits.h:374:8:   
# |   374 |         using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
# |       |               ^~~~~~~~~~~~~
# | required from here
# | /home/jwakely/src/llvm/llvm-project/libcxx/test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp:68:86:   
# |    68 |     static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_traits<double>, std::allocator_traits<ReboundA<double> > >::value), "");
# |       |                                                                                      ^
# | /home/jwakely/gcc/16/include/c++/16.0.0/bits/alloc_traits.h:85:31: error: static assertion failed: allocator_traits<A>::rebind_alloc<A::value_type> must be A
# |    85 |                         _Tp>::value,
# |       |                               ^~~~~
```

I assume the point of this test is to verify that `rebind_traits` does actually use `A<T>::rebind<U>::other` when that's defined, and doesn't just unconditionally substitute `U` into `A`. I'm not sure how to test that without violating the requirements though.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to