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

Implement LWG-3743 ranges::to's reserve may be ill-formed #3269

Merged
merged 8 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -7588,7 +7588,7 @@ namespace ranges {
} else if constexpr (_Converts_constructible_insertable<_Rng, _Container, _Types...>) {
_Container _Cont(_STD forward<_Types>(_Args)...);
if constexpr (_Sized_and_reservable<_Rng, _Container>) {
_Cont.reserve(_RANGES size(_Range));
_Cont.reserve(static_cast<range_size_t<_Container>>(_RANGES size(_Range)));
}
_RANGES copy(_Range, _Container_inserter<range_reference_t<_Rng>>(_Cont));
return _Cont;
Expand Down
7 changes: 7 additions & 0 deletions stl/inc/xutility
Original file line number Diff line number Diff line change
Expand Up @@ -3617,6 +3617,10 @@ namespace ranges {
constexpr explicit _Subrange_base(const _Size_type&) noexcept {}
};

#if 1 // TRANSITION, VSO-1695918 - Warning C4324 incorrectly firing in the presence of `pragma pack`
#pragma warning(push)
#pragma warning(disable : 4324) // structure was padded due to alignment specifier
fsb4000 marked this conversation as resolved.
Show resolved Hide resolved
#endif // TRANSITION, VSO-1695918 - Warning C4324 incorrectly firing in the presence of `pragma pack`
_EXPORT_STD template <input_or_output_iterator _It, sentinel_for<_It> _Se, subrange_kind _Ki>
requires (_Ki == subrange_kind::sized || !sized_sentinel_for<_Se, _It>)
class subrange : public _Subrange_base<_It, _Se, _Ki> {
Expand Down Expand Up @@ -3779,6 +3783,9 @@ namespace ranges {
return *this;
}
};
#if 1 // TRANSITION, VSO-1695918 - Warning C4324 incorrectly firing in the presence of `pragma pack`
#pragma warning(pop)
#endif // TRANSITION, VSO-1695918 - Warning C4324 incorrectly firing in the presence of `pragma pack`

template <input_or_output_iterator _It, sentinel_for<_It> _Se>
subrange(_It, _Se) -> subrange<_It, _Se>;
Expand Down
5 changes: 5 additions & 0 deletions tests/std/tests/P1206R7_vector_from_range/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ void test_vso1591034() {
assert(counted_item::count == 6);
}

void test_LWG_3743() { // COMPILE-ONLY
ranges::subrange r(views::iota(0ULL) | views::take(5), 5);
(void) ranges::to<vector<unsigned long long>>(r, size_t{0});
}

int main() {
// Validate views
test_copyable_views();
Expand Down