Non-portable test for allocator_traits::rebind_traits
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
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::rebind_alloc` 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, double>’:
# | required by substitution of ‘template template using std::allocator_traits< >::rebind_traits = std::allocator_traits::type> [with _Tp = double; _Alloc = A]’
# | /home/jwakely/gcc/16/include/c++/16.0.0/bits/alloc_traits.h:374:8:
# | 374 | using rebind_traits = allocator_traits>;
# | | ^~~~~~~~~~~~~
# | 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 >::rebind_traits, std::allocator_traits > >::value), "");
# | | ^
# | /home/jwakely/gcc/16/include/c++/16.0.0/bits/alloc_traits.h:85:31: error: static assertion failed: allocator_traits::rebind_alloc must be A
# | 85 | _Tp>::value,
# | | ^~~~~
```
I assume the point of this test is to verify that `rebind_traits` does actually use `A::rebind::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.
Contributor guide
Research direction
Start with libcxx/test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp, especially the allocator types and static assertions around lines 31 and 68, then run this test with libstdc++. Check the Cpp17Allocator requirement and the reported rebind_traits failure; done means the test still verifies the intended rebind behavior without failing for a non-portable allocator definition.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100