Skip to content

Commit a66a092

Browse files
fsb4000CaseyCarterStephanTLavavej
authored
Implement LWG-3743 ranges::to's reserve may be ill-formed (#3269)
Co-authored-by: Casey Carter <[email protected]> Co-authored-by: Stephan T. Lavavej <[email protected]>
1 parent f1e026f commit a66a092

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

stl/inc/ranges

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7720,7 +7720,7 @@ namespace ranges {
77207720
} else if constexpr (_Converts_constructible_insertable<_Rng, _Container, _Types...>) {
77217721
_Container _Cont(_STD forward<_Types>(_Args)...);
77227722
if constexpr (_Sized_and_reservable<_Rng, _Container>) {
7723-
_Cont.reserve(_RANGES size(_Range));
7723+
_Cont.reserve(static_cast<range_size_t<_Container>>(_RANGES size(_Range)));
77247724
}
77257725
_RANGES copy(_Range, _Container_inserter<range_reference_t<_Rng>>(_Cont));
77267726
return _Cont;

stl/inc/xutility

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3630,6 +3630,10 @@ namespace ranges {
36303630
constexpr explicit _Subrange_base(const _Size_type&) noexcept {}
36313631
};
36323632

3633+
#if 1 // TRANSITION, VSO-1695918 - Warning C4324 incorrectly firing in the presence of `pragma pack`
3634+
#pragma warning(push)
3635+
#pragma warning(disable : 4324) // structure was padded due to alignment specifier
3636+
#endif // TRANSITION, VSO-1695918 - Warning C4324 incorrectly firing in the presence of `pragma pack`
36333637
_EXPORT_STD template <input_or_output_iterator _It, sentinel_for<_It> _Se, subrange_kind _Ki>
36343638
requires (_Ki == subrange_kind::sized || !sized_sentinel_for<_Se, _It>)
36353639
class subrange : public _Subrange_base<_It, _Se, _Ki> {
@@ -3792,6 +3796,9 @@ namespace ranges {
37923796
return *this;
37933797
}
37943798
};
3799+
#if 1 // TRANSITION, VSO-1695918 - Warning C4324 incorrectly firing in the presence of `pragma pack`
3800+
#pragma warning(pop)
3801+
#endif // TRANSITION, VSO-1695918 - Warning C4324 incorrectly firing in the presence of `pragma pack`
37953802

37963803
template <input_or_output_iterator _It, sentinel_for<_It> _Se>
37973804
subrange(_It, _Se) -> subrange<_It, _Se>;

tests/std/tests/P1206R7_vector_from_range/test.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ void test_vso1591034() {
161161
assert(counted_item::count == 6);
162162
}
163163

164+
void test_LWG_3743() { // COMPILE-ONLY
165+
ranges::subrange r(views::iota(0ULL) | views::take(5), 5);
166+
(void) ranges::to<vector<unsigned long long>>(r, size_t{0});
167+
}
168+
164169
int main() {
165170
// Validate views
166171
test_copyable_views();

0 commit comments

Comments
 (0)