[libcxx-commits] [libcxx] [libc++] Fix ambiguous call to std::max in vector<bool> (PR #119801)
Peng Liu via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Mar 14 21:23:55 PDT 2025
https://github.com/winner245 updated https://github.com/llvm/llvm-project/pull/119801
>From 20796d5c7126899a066a3bcb52eb1db93592927b Mon Sep 17 00:00:00 2001
From: Peng Liu <winner245 at hotmail.com>
Date: Thu, 12 Dec 2024 21:33:15 -0500
Subject: [PATCH 1/3] Fix ambiguous call to std::max in vector<bool>
---
libcxx/include/__cxx03/string | 8 ++++++--
libcxx/include/__cxx03/vector | 2 +-
libcxx/include/__vector/vector_bool.h | 2 +-
libcxx/include/string | 2 +-
4 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/libcxx/include/__cxx03/string b/libcxx/include/__cxx03/string
index c4431dcb04d41..c29f74290bd41 100644
--- a/libcxx/include/__cxx03/string
+++ b/libcxx/include/__cxx03/string
@@ -2483,7 +2483,9 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__
__throw_length_error();
pointer __old_p = __get_pointer();
size_type __cap =
- __old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms - 1;
+ __old_cap < __ms / 2 - __alignment
+ ? __recommend(std::max<size_type>(__old_cap + __delta_cap, 2 * __old_cap))
+ : __ms - 1;
__annotate_delete();
auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
pointer __p = __allocation.ptr;
@@ -2526,7 +2528,9 @@ _LIBCPP_DEPRECATED_("use __grow_by_without_replace") basic_string<_CharT, _Trait
__throw_length_error();
pointer __old_p = __get_pointer();
size_type __cap =
- __old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms - 1;
+ __old_cap < __ms / 2 - __alignment
+ ? __recommend(std::max<size_type>(__old_cap + __delta_cap, 2 * __old_cap))
+ : __ms - 1;
__annotate_delete();
auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
pointer __p = __allocation.ptr;
diff --git a/libcxx/include/__cxx03/vector b/libcxx/include/__cxx03/vector
index 6ee35b4e36258..80da74ded67b7 100644
--- a/libcxx/include/__cxx03/vector
+++ b/libcxx/include/__cxx03/vector
@@ -2328,7 +2328,7 @@ vector<bool, _Allocator>::__recommend(size_type __new_size) const {
const size_type __cap = capacity();
if (__cap >= __ms / 2)
return __ms;
- return std::max(2 * __cap, __align_it(__new_size));
+ return std::max<size_type>(2 * __cap, __align_it(__new_size));
}
// Default constructs __n objects starting at __end_
diff --git a/libcxx/include/__vector/vector_bool.h b/libcxx/include/__vector/vector_bool.h
index b02b0dc1725f2..a888b9ab9fcc0 100644
--- a/libcxx/include/__vector/vector_bool.h
+++ b/libcxx/include/__vector/vector_bool.h
@@ -549,7 +549,7 @@ vector<bool, _Allocator>::__recommend(size_type __new_size) const {
const size_type __cap = capacity();
if (__cap >= __ms / 2)
return __ms;
- return std::max(2 * __cap, __align_it(__new_size));
+ return std::max<size_type>(2 * __cap, __align_it(__new_size));
}
// Default constructs __n objects starting at __end_
diff --git a/libcxx/include/string b/libcxx/include/string
index ea9ba24084a3b..fa16cf6302590 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -2623,7 +2623,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__
__throw_length_error();
pointer __old_p = __get_pointer();
size_type __cap =
- __old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms;
+ __old_cap < __ms / 2 - __alignment ? __recommend(std::max<size_type>(__old_cap + __delta_cap, 2 * __old_cap)) : __ms;
__annotate_delete();
auto __guard = std::__make_scope_guard(__annotate_new_size(*this));
auto __allocation = std::__allocate_at_least(__alloc_, __cap + 1);
>From 3c84df6ba855b5cab8317ca8dc929f8b8d1934f7 Mon Sep 17 00:00:00 2001
From: Peng Liu <winner245 at hotmail.com>
Date: Thu, 9 Jan 2025 08:42:10 -0500
Subject: [PATCH 2/3] Add new tests
---
.../vector.bool/sized_allocator.pass.cpp | 121 ++++++++++++++++++
1 file changed, 121 insertions(+)
create mode 100644 libcxx/test/std/containers/sequences/vector.bool/sized_allocator.pass.cpp
diff --git a/libcxx/test/std/containers/sequences/vector.bool/sized_allocator.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/sized_allocator.pass.cpp
new file mode 100644
index 0000000000000..0964f3a57ed70
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/vector.bool/sized_allocator.pass.cpp
@@ -0,0 +1,121 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <vector>
+// vector<bool>
+
+// This test examines ambiguous calls to std::max in vector<bool>
+// Fix https://github.com/llvm/llvm-project/issues/121713
+
+#include <cassert>
+#include <cstddef>
+#include <cstdint>
+#include <limits>
+#include <memory>
+#include <new>
+#include <vector>
+
+#include "test_macros.h"
+
+template <typename T, typename SIZE_TYPE = std::size_t, typename DIFF_TYPE = std::ptrdiff_t>
+class sized_allocator {
+ template <typename U, typename Sz, typename Diff>
+ friend class sized_allocator;
+
+public:
+ using value_type = T;
+ using size_type = SIZE_TYPE;
+ using difference_type = DIFF_TYPE;
+ using propagate_on_container_swap = std::true_type;
+
+ TEST_CONSTEXPR_CXX20 explicit sized_allocator(int d = 0) : data_(d) {}
+
+ template <typename U, typename Sz, typename Diff>
+ TEST_CONSTEXPR_CXX20 sized_allocator(const sized_allocator<U, Sz, Diff>& a) TEST_NOEXCEPT : data_(a.data_) {}
+
+ TEST_CONSTEXPR_CXX20 T* allocate(size_type n) {
+ if (n > max_size())
+ TEST_THROW(std::bad_array_new_length());
+ return std::allocator<T>().allocate(n);
+ }
+
+ TEST_CONSTEXPR_CXX20 void deallocate(T* p, size_type n) TEST_NOEXCEPT { std::allocator<T>().deallocate(p, n); }
+
+ TEST_CONSTEXPR size_type max_size() const TEST_NOEXCEPT {
+ return std::numeric_limits<size_type>::max() / sizeof(value_type);
+ }
+
+private:
+ int data_;
+
+ TEST_CONSTEXPR friend bool operator==(const sized_allocator& a, const sized_allocator& b) {
+ return a.data_ == b.data_;
+ }
+ TEST_CONSTEXPR friend bool operator!=(const sized_allocator& a, const sized_allocator& b) {
+ return a.data_ != b.data_;
+ }
+};
+
+TEST_CONSTEXPR_CXX20 bool tests() {
+ // The following tests are typical ways to trigger reallocations where `std::max` is used to calculate the capacity.
+ {
+ using Alloc = sized_allocator<bool, std::uint8_t, std::int8_t>;
+ std::vector<bool, Alloc> c(Alloc(1));
+ c.resize(10);
+ }
+ {
+ using Alloc = sized_allocator<bool, std::uint8_t, std::int8_t>;
+ std::vector<bool, Alloc> c(Alloc(1));
+ c.assign(10, true);
+ }
+ {
+ using Alloc = sized_allocator<bool, std::uint8_t, std::int8_t>;
+ std::vector<bool, Alloc> c(Alloc(1));
+ c.insert(c.end(), true);
+ }
+ {
+ using Alloc = sized_allocator<bool, std::uint16_t, std::int16_t>;
+ std::vector<bool, Alloc> c(Alloc(1));
+ c.insert(c.end(), 10, true);
+ }
+ {
+ using Alloc = sized_allocator<bool, std::uint16_t, std::int16_t>;
+ std::vector<bool, Alloc> c(Alloc(1));
+ c.push_back(true);
+ }
+ {
+ using Alloc = sized_allocator<bool, std::uint16_t, std::int16_t>;
+ std::vector<bool, Alloc> c(Alloc(1));
+ c.resize(10, true);
+ }
+ {
+ using Alloc = sized_allocator<bool, std::uint32_t, std::int32_t>;
+ std::vector<bool, Alloc> c(Alloc(1));
+ c.resize(10);
+ }
+ {
+ using Alloc = sized_allocator<bool, std::uint64_t, std::int64_t>;
+ std::vector<bool, Alloc> c(Alloc(1));
+ c.resize(10);
+ }
+ {
+ using Alloc = sized_allocator<bool, std::size_t, std::ptrdiff_t>;
+ std::vector<bool, Alloc> c(Alloc(1));
+ c.resize(10);
+ }
+
+ return true;
+}
+
+int main(int, char**) {
+ tests();
+#if TEST_STD_VER >= 20
+ static_assert(tests());
+#endif
+ return 0;
+}
>From 4d4fd15e4fc7cfe92809a1783ebad70e69e0bd22 Mon Sep 17 00:00:00 2001
From: Peng Liu <winner245 at hotmail.com>
Date: Wed, 15 Jan 2025 13:04:11 -0500
Subject: [PATCH 3/3] Address ldionne's comments
---
libcxx/include/__cxx03/string | 8 +--
libcxx/include/__cxx03/vector | 51 ++++++++--------
libcxx/include/string | 2 +-
.../vector.bool/sized_allocator.pass.cpp | 59 +++++++------------
4 files changed, 48 insertions(+), 72 deletions(-)
diff --git a/libcxx/include/__cxx03/string b/libcxx/include/__cxx03/string
index c29f74290bd41..c4431dcb04d41 100644
--- a/libcxx/include/__cxx03/string
+++ b/libcxx/include/__cxx03/string
@@ -2483,9 +2483,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__
__throw_length_error();
pointer __old_p = __get_pointer();
size_type __cap =
- __old_cap < __ms / 2 - __alignment
- ? __recommend(std::max<size_type>(__old_cap + __delta_cap, 2 * __old_cap))
- : __ms - 1;
+ __old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms - 1;
__annotate_delete();
auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
pointer __p = __allocation.ptr;
@@ -2528,9 +2526,7 @@ _LIBCPP_DEPRECATED_("use __grow_by_without_replace") basic_string<_CharT, _Trait
__throw_length_error();
pointer __old_p = __get_pointer();
size_type __cap =
- __old_cap < __ms / 2 - __alignment
- ? __recommend(std::max<size_type>(__old_cap + __delta_cap, 2 * __old_cap))
- : __ms - 1;
+ __old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms - 1;
__annotate_delete();
auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
pointer __p = __allocation.ptr;
diff --git a/libcxx/include/__cxx03/vector b/libcxx/include/__cxx03/vector
index 80da74ded67b7..c8aa828550c86 100644
--- a/libcxx/include/__cxx03/vector
+++ b/libcxx/include/__cxx03/vector
@@ -564,8 +564,8 @@ public:
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
#endif
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
- vector(vector&& __x, const __type_identity_t<allocator_type>& __a);
+ _LIBCPP_CONSTEXPR_SINCE_CXX20
+ _LIBCPP_HIDE_FROM_ABI vector(vector&& __x, const __type_identity_t<allocator_type>& __a);
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector& operator=(vector&& __x)
_NOEXCEPT_(__noexcept_move_assign_container<_Allocator, __alloc_traits>::value);
@@ -681,11 +681,9 @@ public:
template <class... _Args>
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
#if _LIBCPP_STD_VER >= 17
- reference
- emplace_back(_Args&&... __args);
+ reference emplace_back(_Args&&... __args);
#else
- void
- emplace_back(_Args&&... __args);
+ void emplace_back(_Args&&... __args);
#endif
#if _LIBCPP_STD_VER >= 23
@@ -731,12 +729,12 @@ public:
__enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
is_constructible< value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
int> = 0>
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
- insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
+ _LIBCPP_CONSTEXPR_SINCE_CXX20
+ _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
#ifndef _LIBCPP_CXX03_LANG
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
- insert(const_iterator __position, initializer_list<value_type> __il) {
+ _LIBCPP_CONSTEXPR_SINCE_CXX20
+ _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, initializer_list<value_type> __il) {
return insert(__position, __il.begin(), __il.end());
}
#endif
@@ -1279,8 +1277,8 @@ vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
-_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI
-vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il) {
+_LIBCPP_CONSTEXPR_SINCE_CXX20 inline
+ _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il) {
auto __guard = std::__make_exception_guard(__destroy_vector(*this));
if (__il.size() > 0) {
__vallocate(__il.size());
@@ -1304,9 +1302,9 @@ vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocat
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
-_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>&
-vector<_Tp, _Allocator>::operator=(vector&& __x)
- _NOEXCEPT_(__noexcept_move_assign_container<_Allocator, __alloc_traits>::value) {
+_LIBCPP_CONSTEXPR_SINCE_CXX20 inline
+ _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>& vector<_Tp, _Allocator>::operator=(vector&& __x)
+ _NOEXCEPT_(__noexcept_move_assign_container<_Allocator, __alloc_traits>::value) {
__move_assign(__x, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>());
return *this;
}
@@ -1995,8 +1993,8 @@ public:
#else
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
#endif
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
- vector(vector&& __v, const __type_identity_t<allocator_type>& __a);
+ _LIBCPP_HIDE_FROM_ABI
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(vector&& __v, const __type_identity_t<allocator_type>& __a);
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector& operator=(vector&& __v)
_NOEXCEPT_(__noexcept_move_assign_container<_Allocator, __alloc_traits>::value);
@@ -2138,8 +2136,8 @@ public:
#endif
#ifndef _LIBCPP_CXX03_LANG
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
- insert(const_iterator __position, initializer_list<value_type> __il) {
+ _LIBCPP_HIDE_FROM_ABI
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __position, initializer_list<value_type> __il) {
return insert(__position, __il.begin(), __il.end());
}
#endif
@@ -2328,7 +2326,7 @@ vector<bool, _Allocator>::__recommend(size_type __new_size) const {
const size_type __cap = capacity();
if (__cap >= __ms / 2)
return __ms;
- return std::max<size_type>(2 * __cap, __align_it(__new_size));
+ return std::max(2 * __cap, __align_it(__new_size));
}
// Default constructs __n objects starting at __end_
@@ -2894,8 +2892,8 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t vector<bool, _Allocator>::__hash_code() con
}
template <class _Allocator>
-struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
- : public __unary_function<vector<bool, _Allocator>, size_t> {
+struct _LIBCPP_TEMPLATE_VIS
+hash<vector<bool, _Allocator> > : public __unary_function<vector<bool, _Allocator>, size_t> {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t
operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT {
return __vec.__hash_code();
@@ -2947,15 +2945,16 @@ operator<=>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& _
#endif // _LIBCPP_STD_VER <= 17
template <class _Tp, class _Allocator>
-_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void
-swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
+_LIBCPP_CONSTEXPR_SINCE_CXX20 inline
+ _LIBCPP_HIDE_FROM_ABI void swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
+ _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
__x.swap(__y);
}
#if _LIBCPP_STD_VER >= 20
template <class _Tp, class _Allocator, class _Up>
-_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
-erase(vector<_Tp, _Allocator>& __c, const _Up& __v) {
+_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI
+typename vector<_Tp, _Allocator>::size_type erase(vector<_Tp, _Allocator>& __c, const _Up& __v) {
auto __old_size = __c.size();
__c.erase(std::remove(__c.begin(), __c.end(), __v), __c.end());
return __old_size - __c.size();
diff --git a/libcxx/include/string b/libcxx/include/string
index fa16cf6302590..ea9ba24084a3b 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -2623,7 +2623,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__
__throw_length_error();
pointer __old_p = __get_pointer();
size_type __cap =
- __old_cap < __ms / 2 - __alignment ? __recommend(std::max<size_type>(__old_cap + __delta_cap, 2 * __old_cap)) : __ms;
+ __old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms;
__annotate_delete();
auto __guard = std::__make_scope_guard(__annotate_new_size(*this));
auto __allocation = std::__allocate_at_least(__alloc_, __cap + 1);
diff --git a/libcxx/test/std/containers/sequences/vector.bool/sized_allocator.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/sized_allocator.pass.cpp
index 0964f3a57ed70..a322dd4f8649e 100644
--- a/libcxx/test/std/containers/sequences/vector.bool/sized_allocator.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector.bool/sized_allocator.pass.cpp
@@ -20,93 +20,74 @@
#include <new>
#include <vector>
+#include "sized_allocator.h"
#include "test_macros.h"
-template <typename T, typename SIZE_TYPE = std::size_t, typename DIFF_TYPE = std::ptrdiff_t>
-class sized_allocator {
- template <typename U, typename Sz, typename Diff>
- friend class sized_allocator;
-
-public:
- using value_type = T;
- using size_type = SIZE_TYPE;
- using difference_type = DIFF_TYPE;
- using propagate_on_container_swap = std::true_type;
-
- TEST_CONSTEXPR_CXX20 explicit sized_allocator(int d = 0) : data_(d) {}
-
- template <typename U, typename Sz, typename Diff>
- TEST_CONSTEXPR_CXX20 sized_allocator(const sized_allocator<U, Sz, Diff>& a) TEST_NOEXCEPT : data_(a.data_) {}
-
- TEST_CONSTEXPR_CXX20 T* allocate(size_type n) {
- if (n > max_size())
- TEST_THROW(std::bad_array_new_length());
- return std::allocator<T>().allocate(n);
- }
-
- TEST_CONSTEXPR_CXX20 void deallocate(T* p, size_type n) TEST_NOEXCEPT { std::allocator<T>().deallocate(p, n); }
-
- TEST_CONSTEXPR size_type max_size() const TEST_NOEXCEPT {
- return std::numeric_limits<size_type>::max() / sizeof(value_type);
- }
-
-private:
- int data_;
-
- TEST_CONSTEXPR friend bool operator==(const sized_allocator& a, const sized_allocator& b) {
- return a.data_ == b.data_;
- }
- TEST_CONSTEXPR friend bool operator!=(const sized_allocator& a, const sized_allocator& b) {
- return a.data_ != b.data_;
- }
-};
-
TEST_CONSTEXPR_CXX20 bool tests() {
// The following tests are typical ways to trigger reallocations where `std::max` is used to calculate the capacity.
+ // The purpose of these tests is to ensure that the ambiguous internal calls to `std::max` have been fixed.
{
using Alloc = sized_allocator<bool, std::uint8_t, std::int8_t>;
std::vector<bool, Alloc> c(Alloc(1));
c.resize(10);
+ assert(c.size() == 10);
+ assert(c.capacity() >= 10);
}
{
using Alloc = sized_allocator<bool, std::uint8_t, std::int8_t>;
std::vector<bool, Alloc> c(Alloc(1));
c.assign(10, true);
+ assert(c.size() == 10);
+ assert(c.capacity() >= 10);
}
{
using Alloc = sized_allocator<bool, std::uint8_t, std::int8_t>;
std::vector<bool, Alloc> c(Alloc(1));
c.insert(c.end(), true);
+ assert(c.size() == 1);
+ assert(c.capacity() >= 1);
}
{
using Alloc = sized_allocator<bool, std::uint16_t, std::int16_t>;
std::vector<bool, Alloc> c(Alloc(1));
c.insert(c.end(), 10, true);
+ assert(c.size() == 10);
+ assert(c.capacity() >= 10);
}
{
using Alloc = sized_allocator<bool, std::uint16_t, std::int16_t>;
std::vector<bool, Alloc> c(Alloc(1));
c.push_back(true);
+ assert(c.size() == 1);
+ assert(c.capacity() >= 1);
}
{
using Alloc = sized_allocator<bool, std::uint16_t, std::int16_t>;
std::vector<bool, Alloc> c(Alloc(1));
c.resize(10, true);
+ assert(c.size() == 10);
+ assert(c.capacity() >= 10);
}
{
using Alloc = sized_allocator<bool, std::uint32_t, std::int32_t>;
std::vector<bool, Alloc> c(Alloc(1));
c.resize(10);
+ assert(c.size() == 10);
+ assert(c.capacity() >= 10);
}
{
using Alloc = sized_allocator<bool, std::uint64_t, std::int64_t>;
std::vector<bool, Alloc> c(Alloc(1));
c.resize(10);
+ assert(c.size() == 10);
+ assert(c.capacity() >= 10);
}
{
using Alloc = sized_allocator<bool, std::size_t, std::ptrdiff_t>;
std::vector<bool, Alloc> c(Alloc(1));
c.resize(10);
+ assert(c.size() == 10);
+ assert(c.capacity() >= 10);
}
return true;
More information about the libcxx-commits
mailing list