[libcxx-commits] [libcxx] [libc++] Use __alloc_traits whenever it is available for consistency (PR #126595)

Peng Liu via libcxx-commits libcxx-commits at lists.llvm.org
Tue Feb 11 09:25:53 PST 2025


================
@@ -719,7 +719,7 @@ public:
   _LIBCPP_HIDE_FROM_ABI forward_list& operator=(forward_list&& __x) noexcept(
       (__node_traits::propagate_on_container_move_assignment::value &&
        is_nothrow_move_assignable<allocator_type>::value) ||
-      allocator_traits<allocator_type>::is_always_equal::value);
+      __node_traits::is_always_equal::value);
----------------
winner245 wrote:

> I think if the allocator provided as template argument and the rebound have different propagation properties and behaves differently on propagation, then it is difficult or impossible for implementations to follow the current exception specifications.

I strongly agree with this statement from [LWG3267](https://cplusplus.github.io/LWG/issue3267). This also explains why the three major standard implementations all made the implicit assumption that the original and rebound allocator_traits have the same propagation properties. 

After further investigation of libc++ implementation of `vector<bool>`, I observed instances where the original `__alloc_traits` and rebound `__storage_traits` are used interchangeably, e.g., 

https://github.com/llvm/llvm-project/blob/43c82a8e07819ad0553ef0dffedff3c8b8cecf5e/libcxx/include/__vector/vector_bool.h#L759-L765

where the noexcept specification asserts on the original `__alloc_traits`, while the implementation is based on the rebound `__storage_traits`. For other cases, it's mainly the rebound `__storage_traits` used in both the noexcept specification and the implementation, for example,

https://github.com/llvm/llvm-project/blob/43c82a8e07819ad0553ef0dffedff3c8b8cecf5e/libcxx/include/__vector/vector_bool.h#L500-L505

I am not sure whether we should make these usages consistent or continue to rely on the implicit assumption while somehow making the assumption more explicit.


https://github.com/llvm/llvm-project/pull/126595


More information about the libcxx-commits mailing list