Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<list>, <string>: Remove allocator-moving tagged internal constructors #4976

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions stl/inc/list
Original file line number Diff line number Diff line change
Expand Up @@ -804,11 +804,6 @@ public:
}

private:
template <class _Any_alloc>
explicit list(_Move_allocator_tag, _Any_alloc& _Al) : _Mypair(_One_then_variadic_args_t{}, _STD move(_Al)) {
_Alloc_sentinel_and_proxy();
}

void _Construct_n(_CRT_GUARDOVERFLOW size_type _Count) {
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Getal());
_Container_proxy_ptr<_Alty> _Proxy(_Alproxy, _Mypair._Myval2);
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/sstream
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public:
// the buffer may already be full, and the terminating char is not '\0'.
// In that case, copy the string as usual.
_NODISCARD _Mystr str() && {
_Mystr _Result{_String_constructor_rvalue_allocator_tag{}, _STD move(_Al)};
_Mystr _Result{_Al};
const auto _View = _Get_buffer_view();
// _Size cannot be larger than _Res, but it could be equal,
// because basic_stringbuf doesn't allocate for the terminating '\0'.
Expand Down
5 changes: 2 additions & 3 deletions stl/inc/xhash
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,9 @@ protected:
}

_Hash(_Hash&& _Right)
: _Traitsobj(_Right._Traitsobj), _List(_Move_allocator_tag{}, _Right._List._Getal()),
: _Traitsobj(_Right._Traitsobj), _List(_STD move(_Right._List)),
_Vec(_STD move(_Right._Vec._Mypair._Get_first())) {
_Vec._Assign_grow(_Min_buckets * 2, _Unchecked_end());
_List._Swap_val(_Right._List);
_Vec._Assign_grow(_Min_buckets * 2, _Right._Unchecked_end());
_Vec._Mypair._Myval2._Swap_val(_Right._Vec._Mypair._Myval2);
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
_Mask = _STD exchange(_Right._Mask, _Min_buckets - 1);
_Maxidx = _STD exchange(_Right._Maxidx, _Min_buckets);
Expand Down
4 changes: 0 additions & 4 deletions stl/inc/xmemory
Original file line number Diff line number Diff line change
Expand Up @@ -1535,10 +1535,6 @@ public:
}
};

struct _Move_allocator_tag {
explicit _Move_allocator_tag() = default;
};

template <class _Ty>
pair<_Ty*, ptrdiff_t> _Get_temporary_buffer(ptrdiff_t _Count) noexcept {
if (static_cast<size_t>(_Count) <= static_cast<size_t>(-1) / sizeof(_Ty)) {
Expand Down
11 changes: 0 additions & 11 deletions stl/inc/xstring
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,6 @@ struct _String_constructor_concat_tag {
explicit _String_constructor_concat_tag() = default;
};

struct _String_constructor_rvalue_allocator_tag {
// tag to select constructors used by basic_stringbuf's rvalue str()
explicit _String_constructor_rvalue_allocator_tag() = default;
};

[[noreturn]] inline void _Xlen_string() {
_Xlength_error("string too long");
}
Expand Down Expand Up @@ -1145,12 +1140,6 @@ public:
#endif // _HAS_CXX17

#if _HAS_CXX20
basic_string(_String_constructor_rvalue_allocator_tag, _Alloc&& _Al)
: _Mypair(_One_then_variadic_args_t{}, _STD move(_Al)) {
// Used exclusively by basic_stringbuf
_Construct_empty();
}

_NODISCARD bool _Move_assign_from_buffer(
_Elem* const _Right, const size_type _Size, const size_type _Actual_allocation_size) {
// Move assign from a buffer, used exclusively by basic_stringbuf; returns _Large_mode_engaged()
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ tests\GH_004618_mixed_operator_usage_keeps_statistical_properties
tests\GH_004618_normal_distribution_avoids_resets
tests\GH_004657_expected_constraints_permissive
tests\GH_004845_logical_operator_traits_with_non_bool_constant
tests\GH_004929_internal_tag_constructors
tests\GH_004930_char_traits_user_specialization
tests\LWG2381_num_get_floating_point
tests\LWG2597_complex_branch_cut
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/GH_004929_internal_tag_constructors/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\usual_matrix.lst
95 changes: 95 additions & 0 deletions tests/std/tests/GH_004929_internal_tag_constructors/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <cassert>
#include <list>
#include <memory>
#include <string>
#include <type_traits>
#if _HAS_CXX17
#include <string_view>
#endif // _HAS_CXX17

#if _HAS_CXX20
#define CONSTEXPR20 constexpr
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
#define CONSTEXPR20 inline
#endif // ^^^ !_HAS_CXX20 ^^^

using namespace std;

template <class>
constexpr bool is_initializer_list = false;
template <class T>
constexpr bool is_initializer_list<initializer_list<T>> = true;

template <class T>
constexpr initializer_list<T> ilist42 = {T{'4'}, T{'2'}};

template <class>
constexpr bool is_basic_string_or_cstr_or_view = false;
template <class C, class T, class A>
constexpr bool is_basic_string_or_cstr_or_view<basic_string<C, T, A>> = true;
template <class C>
constexpr bool is_basic_string_or_cstr_or_view<const C*> = true;
#if _HAS_CXX17
template <class C, class T>
constexpr bool is_basic_string_or_cstr_or_view<basic_string_view<C, T>> = true;
#endif // _HAS_CXX17

struct nasty_string_source {
template <class IList, enable_if_t<is_initializer_list<IList>, int> = 0>
constexpr operator IList() const {
return ilist42<typename IList::value_type>;
}

template <class T, enable_if_t<!is_initializer_list<T> && !is_basic_string_or_cstr_or_view<T>, int> = 0>
constexpr operator T() const {
return T{};
}
};

CONSTEXPR20 bool test_nasty_conversion_to_basic_string() {
using namespace std::literals;
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved

assert(string(nasty_string_source{}, allocator<char>{}) == "42"s);
#ifdef __cpp_char8_t
assert(u8string(nasty_string_source{}, allocator<char8_t>{}) == u8"42"s);
#endif // defined (__cpp_char8_t)
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
assert(u16string(nasty_string_source{}, allocator<char16_t>{}) == u"42"s);
assert(u32string(nasty_string_source{}, allocator<char32_t>{}) == U"42"s);
assert(wstring(nasty_string_source{}, allocator<wchar_t>{}) == L"42"s);

return true;
}

template <class>
constexpr bool is_list = false;
template <class T, class A>
constexpr bool is_list<list<T, A>> = true;

struct nasty_list_source {
template <class IList, enable_if_t<is_initializer_list<IList>, int> = 0>
constexpr operator IList() const {
return ilist42<typename IList::value_type>;
}

template <class T, enable_if_t<!is_initializer_list<T> && !is_list<T> && !is_integral_v<T>, int> = 0>
constexpr operator T() const {
return T{};
}
};

void test_nasty_conversion_to_list() {
allocator<int> ator{};
assert((list<int>{nasty_list_source{}, ator} == list<int>{int{'4'}, int{'2'}}));
}

#if _HAS_CXX20
static_assert(test_nasty_conversion_to_basic_string());
#endif // _HAS_CXX20

int main() {
test_nasty_conversion_to_basic_string();
test_nasty_conversion_to_list();
}