Skip to content

Commit 6a4cb62

Browse files
committed
Address ldionne's comments
1 parent 3c84df6 commit 6a4cb62

File tree

4 files changed

+58
-80
lines changed

4 files changed

+58
-80
lines changed

libcxx/include/__cxx03/string

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -728,8 +728,8 @@ operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs, basic_strin
728728

729729
#endif
730730

731-
extern template _LIBCPP_EXPORTED_FROM_ABI string operator+
732-
<char, char_traits<char>, allocator<char> >(char const*, string const&);
731+
extern template
732+
_LIBCPP_EXPORTED_FROM_ABI string operator+ <char, char_traits<char>, allocator<char> >(char const*, string const&);
733733

734734
template <class _Iter>
735735
struct __string_is_trivial_iterator : public false_type {};
@@ -1534,8 +1534,8 @@ public:
15341534
}
15351535
#endif // _LIBCPP_CXX03_LANG
15361536

1537-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1538-
insert(size_type __pos1, const basic_string& __str) {
1537+
_LIBCPP_HIDE_FROM_ABI
1538+
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos1, const basic_string& __str) {
15391539
return insert(__pos1, __str.data(), __str.size());
15401540
}
15411541

@@ -1574,8 +1574,8 @@ public:
15741574
}
15751575
#endif
15761576

1577-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
1578-
insert(const_iterator __pos, size_type __n, value_type __c) {
1577+
_LIBCPP_HIDE_FROM_ABI
1578+
_LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __pos, size_type __n, value_type __c) {
15791579
difference_type __p = __pos - begin();
15801580
insert(static_cast<size_type>(__p), __n, __c);
15811581
return begin() + __p;
@@ -1590,8 +1590,8 @@ public:
15901590
insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
15911591

15921592
#ifndef _LIBCPP_CXX03_LANG
1593-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
1594-
insert(const_iterator __pos, initializer_list<value_type> __il) {
1593+
_LIBCPP_HIDE_FROM_ABI
1594+
_LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __pos, initializer_list<value_type> __il) {
15951595
return insert(__pos, __il.begin(), __il.end());
15961596
}
15971597
#endif // _LIBCPP_CXX03_LANG
@@ -1678,8 +1678,8 @@ public:
16781678
_LIBCPP_CONSTEXPR_SINCE_CXX20 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
16791679

16801680
#if _LIBCPP_STD_VER <= 20
1681-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string
1682-
substr(size_type __pos = 0, size_type __n = npos) const {
1681+
_LIBCPP_HIDE_FROM_ABI
1682+
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string substr(size_type __pos = 0, size_type __n = npos) const {
16831683
return basic_string(*this, __pos, __n);
16841684
}
16851685
#else
@@ -2277,8 +2277,8 @@ template <class _CharT,
22772277
class _Traits,
22782278
class _Allocator = allocator<_CharT>,
22792279
class = enable_if_t<__is_allocator<_Allocator>::value> >
2280-
explicit basic_string(basic_string_view<_CharT, _Traits>,
2281-
const _Allocator& = _Allocator()) -> basic_string<_CharT, _Traits, _Allocator>;
2280+
explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
2281+
-> basic_string<_CharT, _Traits, _Allocator>;
22822282

22832283
template <class _CharT,
22842284
class _Traits,
@@ -2482,10 +2482,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__
24822482
if (__delta_cap > __ms - __old_cap - 1)
24832483
__throw_length_error();
24842484
pointer __old_p = __get_pointer();
2485-
size_type __cap =
2486-
__old_cap < __ms / 2 - __alignment
2487-
? __recommend(std::max<size_type>(__old_cap + __delta_cap, 2 * __old_cap))
2488-
: __ms - 1;
2485+
size_type __cap = __old_cap < __ms / 2 - __alignment ? __recommend(__old_cap + __delta_cap, 2 * __old_cap) : __ms - 1;
24892486
__annotate_delete();
24902487
auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
24912488
pointer __p = __allocation.ptr;
@@ -2528,9 +2525,7 @@ _LIBCPP_DEPRECATED_("use __grow_by_without_replace") basic_string<_CharT, _Trait
25282525
__throw_length_error();
25292526
pointer __old_p = __get_pointer();
25302527
size_type __cap =
2531-
__old_cap < __ms / 2 - __alignment
2532-
? __recommend(std::max<size_type>(__old_cap + __delta_cap, 2 * __old_cap))
2533-
: __ms - 1;
2528+
__old_cap < __ms / 2 - __alignment ? __recommend(std::max__old_cap + __delta_cap, 2 * __old_cap) : __ms - 1;
25342529
__annotate_delete();
25352530
auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
25362531
pointer __p = __allocation.ptr;
@@ -4303,8 +4298,8 @@ operator""s(const char* __str, size_t __len) {
43034298
}
43044299

43054300
# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4306-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<wchar_t>
4307-
operator""s(const wchar_t* __str, size_t __len) {
4301+
inline _LIBCPP_HIDE_FROM_ABI
4302+
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<wchar_t> operator""s(const wchar_t* __str, size_t __len) {
43084303
return basic_string<wchar_t>(__str, __len);
43094304
}
43104305
# endif
@@ -4315,8 +4310,8 @@ inline _LIBCPP_HIDE_FROM_ABI constexpr basic_string<char8_t> operator""s(const c
43154310
}
43164311
# endif
43174312

4318-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<char16_t>
4319-
operator""s(const char16_t* __str, size_t __len) {
4313+
inline _LIBCPP_HIDE_FROM_ABI
4314+
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<char16_t> operator""s(const char16_t* __str, size_t __len) {
43204315
return basic_string<char16_t>(__str, __len);
43214316
}
43224317

libcxx/include/__cxx03/vector

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2328,7 +2328,7 @@ vector<bool, _Allocator>::__recommend(size_type __new_size) const {
23282328
const size_type __cap = capacity();
23292329
if (__cap >= __ms / 2)
23302330
return __ms;
2331-
return std::max<size_type>(2 * __cap, __align_it(__new_size));
2331+
return std::max(2 * __cap, __align_it(__new_size));
23322332
}
23332333

23342334
// Default constructs __n objects starting at __end_

libcxx/include/string

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,8 +1215,8 @@ public:
12151215
return assign(__il.begin(), __il.size());
12161216
}
12171217
# endif
1218-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1219-
operator=(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s) {
1218+
_LIBCPP_HIDE_FROM_ABI
1219+
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s) {
12201220
return assign(__s);
12211221
}
12221222
# if _LIBCPP_STD_VER >= 23
@@ -1520,8 +1520,8 @@ public:
15201520
}
15211521
# endif // _LIBCPP_CXX03_LANG
15221522

1523-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1524-
insert(size_type __pos1, const basic_string& __str) {
1523+
_LIBCPP_HIDE_FROM_ABI
1524+
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos1, const basic_string& __str) {
15251525
return insert(__pos1, __str.data(), __str.size());
15261526
}
15271527

@@ -1560,8 +1560,8 @@ public:
15601560
}
15611561
# endif
15621562

1563-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
1564-
insert(const_iterator __pos, size_type __n, value_type __c) {
1563+
_LIBCPP_HIDE_FROM_ABI
1564+
_LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __pos, size_type __n, value_type __c) {
15651565
difference_type __p = __pos - begin();
15661566
insert(static_cast<size_type>(__p), __n, __c);
15671567
return begin() + __p;
@@ -1576,8 +1576,8 @@ public:
15761576
insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
15771577

15781578
# ifndef _LIBCPP_CXX03_LANG
1579-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
1580-
insert(const_iterator __pos, initializer_list<value_type> __il) {
1579+
_LIBCPP_HIDE_FROM_ABI
1580+
_LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __pos, initializer_list<value_type> __il) {
15811581
return insert(__pos, __il.begin(), __il.end());
15821582
}
15831583
# endif // _LIBCPP_CXX03_LANG
@@ -1664,8 +1664,8 @@ public:
16641664
_LIBCPP_CONSTEXPR_SINCE_CXX20 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
16651665

16661666
# if _LIBCPP_STD_VER <= 20
1667-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string
1668-
substr(size_type __pos = 0, size_type __n = npos) const {
1667+
_LIBCPP_HIDE_FROM_ABI
1668+
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string substr(size_type __pos = 0, size_type __n = npos) const {
16691669
return basic_string(*this, __pos, __n);
16701670
}
16711671
# else
@@ -2441,8 +2441,8 @@ template <class _CharT,
24412441
class _Traits,
24422442
class _Allocator = allocator<_CharT>,
24432443
class = enable_if_t<__is_allocator<_Allocator>::value> >
2444-
explicit basic_string(basic_string_view<_CharT, _Traits>,
2445-
const _Allocator& = _Allocator()) -> basic_string<_CharT, _Traits, _Allocator>;
2444+
explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
2445+
-> basic_string<_CharT, _Traits, _Allocator>;
24462446

24472447
template <class _CharT,
24482448
class _Traits,
@@ -2623,7 +2623,9 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__
26232623
__throw_length_error();
26242624
pointer __old_p = __get_pointer();
26252625
size_type __cap =
2626-
__old_cap < __ms / 2 - __alignment ? __recommend(std::max<size_type>(__old_cap + __delta_cap, 2 * __old_cap)) : __ms;
2626+
__old_cap < __ms / 2 - __alignment
2627+
? __recommend(std::max<size_type>(__old_cap + __delta_cap, 2 * __old_cap))
2628+
: __ms;
26272629
__annotate_delete();
26282630
auto __guard = std::__make_scope_guard(__annotate_new_size(*this));
26292631
auto __allocation = std::__allocate_at_least(__alloc_, __cap + 1);
@@ -4048,8 +4050,8 @@ operator""s(const char* __str, size_t __len) {
40484050
}
40494051

40504052
# if _LIBCPP_HAS_WIDE_CHARACTERS
4051-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<wchar_t>
4052-
operator""s(const wchar_t* __str, size_t __len) {
4053+
inline _LIBCPP_HIDE_FROM_ABI
4054+
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<wchar_t> operator""s(const wchar_t* __str, size_t __len) {
40534055
return basic_string<wchar_t>(__str, __len);
40544056
}
40554057
# endif
@@ -4060,8 +4062,8 @@ inline _LIBCPP_HIDE_FROM_ABI constexpr basic_string<char8_t> operator""s(const c
40604062
}
40614063
# endif
40624064

4063-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<char16_t>
4064-
operator""s(const char16_t* __str, size_t __len) {
4065+
inline _LIBCPP_HIDE_FROM_ABI
4066+
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<char16_t> operator""s(const char16_t* __str, size_t __len) {
40654067
return basic_string<char16_t>(__str, __len);
40664068
}
40674069

libcxx/test/std/containers/sequences/vector.bool/sized_allocator.pass.cpp

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,93 +20,74 @@
2020
#include <new>
2121
#include <vector>
2222

23+
#include "sized_allocator.h"
2324
#include "test_macros.h"
2425

25-
template <typename T, typename SIZE_TYPE = std::size_t, typename DIFF_TYPE = std::ptrdiff_t>
26-
class sized_allocator {
27-
template <typename U, typename Sz, typename Diff>
28-
friend class sized_allocator;
29-
30-
public:
31-
using value_type = T;
32-
using size_type = SIZE_TYPE;
33-
using difference_type = DIFF_TYPE;
34-
using propagate_on_container_swap = std::true_type;
35-
36-
TEST_CONSTEXPR_CXX20 explicit sized_allocator(int d = 0) : data_(d) {}
37-
38-
template <typename U, typename Sz, typename Diff>
39-
TEST_CONSTEXPR_CXX20 sized_allocator(const sized_allocator<U, Sz, Diff>& a) TEST_NOEXCEPT : data_(a.data_) {}
40-
41-
TEST_CONSTEXPR_CXX20 T* allocate(size_type n) {
42-
if (n > max_size())
43-
TEST_THROW(std::bad_array_new_length());
44-
return std::allocator<T>().allocate(n);
45-
}
46-
47-
TEST_CONSTEXPR_CXX20 void deallocate(T* p, size_type n) TEST_NOEXCEPT { std::allocator<T>().deallocate(p, n); }
48-
49-
TEST_CONSTEXPR size_type max_size() const TEST_NOEXCEPT {
50-
return std::numeric_limits<size_type>::max() / sizeof(value_type);
51-
}
52-
53-
private:
54-
int data_;
55-
56-
TEST_CONSTEXPR friend bool operator==(const sized_allocator& a, const sized_allocator& b) {
57-
return a.data_ == b.data_;
58-
}
59-
TEST_CONSTEXPR friend bool operator!=(const sized_allocator& a, const sized_allocator& b) {
60-
return a.data_ != b.data_;
61-
}
62-
};
63-
6426
TEST_CONSTEXPR_CXX20 bool tests() {
6527
// The following tests are typical ways to trigger reallocations where `std::max` is used to calculate the capacity.
28+
// The purpose of these tests is to ensure that the ambiguous internal calls to `std::max` have been fixed.
6629
{
6730
using Alloc = sized_allocator<bool, std::uint8_t, std::int8_t>;
6831
std::vector<bool, Alloc> c(Alloc(1));
6932
c.resize(10);
33+
assert(c.size() == 10);
34+
assert(c.capacity() >= 10);
7035
}
7136
{
7237
using Alloc = sized_allocator<bool, std::uint8_t, std::int8_t>;
7338
std::vector<bool, Alloc> c(Alloc(1));
7439
c.assign(10, true);
40+
assert(c.size() == 10);
41+
assert(c.capacity() >= 10);
7542
}
7643
{
7744
using Alloc = sized_allocator<bool, std::uint8_t, std::int8_t>;
7845
std::vector<bool, Alloc> c(Alloc(1));
7946
c.insert(c.end(), true);
47+
assert(c.size() == 1);
48+
assert(c.capacity() >= 1);
8049
}
8150
{
8251
using Alloc = sized_allocator<bool, std::uint16_t, std::int16_t>;
8352
std::vector<bool, Alloc> c(Alloc(1));
8453
c.insert(c.end(), 10, true);
54+
assert(c.size() == 10);
55+
assert(c.capacity() >= 10);
8556
}
8657
{
8758
using Alloc = sized_allocator<bool, std::uint16_t, std::int16_t>;
8859
std::vector<bool, Alloc> c(Alloc(1));
8960
c.push_back(true);
61+
assert(c.size() == 1);
62+
assert(c.capacity() >= 1);
9063
}
9164
{
9265
using Alloc = sized_allocator<bool, std::uint16_t, std::int16_t>;
9366
std::vector<bool, Alloc> c(Alloc(1));
9467
c.resize(10, true);
68+
assert(c.size() == 10);
69+
assert(c.capacity() >= 10);
9570
}
9671
{
9772
using Alloc = sized_allocator<bool, std::uint32_t, std::int32_t>;
9873
std::vector<bool, Alloc> c(Alloc(1));
9974
c.resize(10);
75+
assert(c.size() == 10);
76+
assert(c.capacity() >= 10);
10077
}
10178
{
10279
using Alloc = sized_allocator<bool, std::uint64_t, std::int64_t>;
10380
std::vector<bool, Alloc> c(Alloc(1));
10481
c.resize(10);
82+
assert(c.size() == 10);
83+
assert(c.capacity() >= 10);
10584
}
10685
{
10786
using Alloc = sized_allocator<bool, std::size_t, std::ptrdiff_t>;
10887
std::vector<bool, Alloc> c(Alloc(1));
10988
c.resize(10);
89+
assert(c.size() == 10);
90+
assert(c.capacity() >= 10);
11091
}
11192

11293
return true;

0 commit comments

Comments
 (0)