Skip to content

Commit a5ea3ea

Browse files
Remove move-allocator tag internal constructors
1 parent 1e312b3 commit a5ea3ea

File tree

8 files changed

+100
-22
lines changed

8 files changed

+100
-22
lines changed

stl/inc/list

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -804,11 +804,6 @@ public:
804804
}
805805

806806
private:
807-
template <class _Any_alloc>
808-
explicit list(_Move_allocator_tag, _Any_alloc& _Al) : _Mypair(_One_then_variadic_args_t{}, _STD move(_Al)) {
809-
_Alloc_sentinel_and_proxy();
810-
}
811-
812807
void _Construct_n(_CRT_GUARDOVERFLOW size_type _Count) {
813808
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Getal());
814809
_Container_proxy_ptr<_Alty> _Proxy(_Alproxy, _Mypair._Myval2);

stl/inc/sstream

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public:
239239
// the buffer may already be full, and the terminating char is not '\0'.
240240
// In that case, copy the string as usual.
241241
_NODISCARD _Mystr str() && {
242-
_Mystr _Result{_String_constructor_rvalue_allocator_tag{}, _STD move(_Al)};
242+
_Mystr _Result{_Al};
243243
const auto _View = _Get_buffer_view();
244244
// _Size cannot be larger than _Res, but it could be equal,
245245
// because basic_stringbuf doesn't allocate for the terminating '\0'.

stl/inc/xhash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ protected:
398398
}
399399

400400
_Hash(_Hash&& _Right)
401-
: _Traitsobj(_Right._Traitsobj), _List(_Move_allocator_tag{}, _Right._List._Getal()),
401+
: _Traitsobj(_Right._Traitsobj), _List(_Right._List._Getal()),
402402
_Vec(_STD move(_Right._Vec._Mypair._Get_first())) {
403403
_Vec._Assign_grow(_Min_buckets * 2, _Unchecked_end());
404404
_List._Swap_val(_Right._List);

stl/inc/xmemory

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,10 +1535,6 @@ public:
15351535
}
15361536
};
15371537

1538-
struct _Move_allocator_tag {
1539-
explicit _Move_allocator_tag() = default;
1540-
};
1541-
15421538
template <class _Ty>
15431539
pair<_Ty*, ptrdiff_t> _Get_temporary_buffer(ptrdiff_t _Count) noexcept {
15441540
if (static_cast<size_t>(_Count) <= static_cast<size_t>(-1) / sizeof(_Ty)) {

stl/inc/xstring

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,6 @@ struct _String_constructor_concat_tag {
508508
explicit _String_constructor_concat_tag() = default;
509509
};
510510

511-
struct _String_constructor_rvalue_allocator_tag {
512-
// tag to select constructors used by basic_stringbuf's rvalue str()
513-
explicit _String_constructor_rvalue_allocator_tag() = default;
514-
};
515-
516511
[[noreturn]] inline void _Xlen_string() {
517512
_Xlength_error("string too long");
518513
}
@@ -1145,12 +1140,6 @@ public:
11451140
#endif // _HAS_CXX17
11461141

11471142
#if _HAS_CXX20
1148-
basic_string(_String_constructor_rvalue_allocator_tag, _Alloc&& _Al)
1149-
: _Mypair(_One_then_variadic_args_t{}, _STD move(_Al)) {
1150-
// Used exclusively by basic_stringbuf
1151-
_Construct_empty();
1152-
}
1153-
11541143
_NODISCARD bool _Move_assign_from_buffer(
11551144
_Elem* const _Right, const size_type _Size, const size_type _Actual_allocation_size) {
11561145
// Move assign from a buffer, used exclusively by basic_stringbuf; returns _Large_mode_engaged()

tests/std/test.lst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ tests\GH_004618_mixed_operator_usage_keeps_statistical_properties
250250
tests\GH_004618_normal_distribution_avoids_resets
251251
tests\GH_004657_expected_constraints_permissive
252252
tests\GH_004845_logical_operator_traits_with_non_bool_constant
253+
tests\GH_004929_internal_tag_constructors
253254
tests\GH_004930_char_traits_user_specialization
254255
tests\LWG2381_num_get_floating_point
255256
tests\LWG2597_complex_branch_cut
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
RUNALL_INCLUDE ..\usual_matrix.lst
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <cassert>
5+
#include <list>
6+
#include <memory>
7+
#include <string>
8+
#include <type_traits>
9+
#if _HAS_CXX17
10+
#include <string_view>
11+
#endif // _HAS_CXX17
12+
13+
#if _HAS_CXX20
14+
#define CONSTEXPR20 constexpr
15+
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
16+
#define CONSTEXPR20 inline
17+
#endif // ^^^ !_HAS_CXX20 ^^^
18+
19+
using namespace std;
20+
21+
template <class>
22+
constexpr bool is_initializer_list = false;
23+
template <class T>
24+
constexpr bool is_initializer_list<initializer_list<T>> = true;
25+
26+
template <class T>
27+
constexpr initializer_list<T> ilist42 = {T{'4'}, T{'2'}};
28+
29+
template <class>
30+
constexpr bool is_basic_string_or_view = false;
31+
template <class C, class T, class A>
32+
constexpr bool is_basic_string_or_view<basic_string<C, T, A>> = true;
33+
#if _HAS_CXX17
34+
template <class C, class T>
35+
constexpr bool is_basic_string_or_view<basic_string_view<C, T>> = true;
36+
#endif // _HAS_CXX17
37+
38+
struct nasty_string_source {
39+
template <class IList, enable_if_t<is_initializer_list<IList>, int> = 0>
40+
constexpr operator IList() const {
41+
return ilist42<typename IList::value_type>;
42+
}
43+
44+
template <class T, enable_if_t<!is_initializer_list<T> && !is_basic_string_or_view<T>, int> = 0>
45+
constexpr operator T() const {
46+
return T{};
47+
}
48+
};
49+
50+
CONSTEXPR20 bool test_nasty_conversion_to_basic_string() {
51+
using namespace std::literals;
52+
53+
assert(string(nasty_string_source{}, allocator<char>{}) == "42"s);
54+
#ifdef __cpp_char8_t
55+
assert(u8string(nasty_string_source{}, allocator<char8_t>{}) == u8"42"s);
56+
#endif // defined (__cpp_char8_t)
57+
assert(u16string(nasty_string_source{}, allocator<char16_t>{}) == u"42"s);
58+
assert(u32string(nasty_string_source{}, allocator<char32_t>{}) == U"42"s);
59+
assert(wstring(nasty_string_source{}, allocator<wchar_t>{}) == L"42"s);
60+
61+
return true;
62+
}
63+
64+
template <class>
65+
constexpr bool is_list = false;
66+
template <class T, class A>
67+
constexpr bool is_list<list<T, A>> = true;
68+
69+
struct nasty_list_source {
70+
template <class IList, enable_if_t<is_initializer_list<IList>, int> = 0>
71+
constexpr operator IList() const {
72+
return ilist42<typename IList::value_type>;
73+
}
74+
75+
template <class T, enable_if_t<!is_initializer_list<T> && !is_list<T> && !is_integral_v<T>, int> = 0>
76+
constexpr operator T() const {
77+
return T{};
78+
}
79+
};
80+
81+
void test_nasty_conversion_to_list() {
82+
allocator<int> ator{};
83+
assert((list<int>{nasty_list_source{}, ator} == list<int>{int{'4'}, int{'2'}}));
84+
}
85+
86+
#if _HAS_CXX20
87+
static_assert(test_nasty_conversion_to_basic_string());
88+
#endif // _HAS_CXX20
89+
90+
int main() {
91+
test_nasty_conversion_to_basic_string();
92+
test_nasty_conversion_to_list();
93+
}

0 commit comments

Comments
 (0)