Skip to content

Commit a537ec5

Browse files
fsb4000hewillkStephanTLavavej
authored
Don't use auto in some ranges algos. (#4841)
Co-authored-by: Hewill Kang <[email protected]> Co-authored-by: Stephan T. Lavavej <[email protected]>
1 parent 0f0f3aa commit a537ec5

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

stl/inc/algorithm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7781,7 +7781,7 @@ namespace ranges {
77817781
void _Rotate_one_right(_It _First, _It _Mid, _It _Last) {
77827782
// exchanges the range [_First, _Mid) with [_Mid, _Last)
77837783
_STL_INTERNAL_CHECK(_RANGES next(_Mid) == _Last);
7784-
auto _Temp = _RANGES iter_move(_Mid);
7784+
iter_value_t<_It> _Temp(_RANGES iter_move(_Mid));
77857785
_RANGES _Move_backward_common(_First, _STD move(_Mid), _STD move(_Last));
77867786
*_First = _STD move(_Temp);
77877787
}
@@ -7790,7 +7790,7 @@ namespace ranges {
77907790
void _Rotate_one_left(_It _First, _It _Mid, _It _Last) {
77917791
// exchanges the range [_First, _Mid) with [_Mid, _Last)
77927792
_STL_INTERNAL_CHECK(_RANGES next(_First) == _Mid);
7793-
auto _Temp = _RANGES iter_move(_First);
7793+
iter_value_t<_It> _Temp(_RANGES iter_move(_First));
77947794
auto _Result = _RANGES _Move_unchecked(_STD move(_Mid), _STD move(_Last), _STD move(_First));
77957795
*_Result.out = _STD move(_Temp);
77967796
}
@@ -10286,7 +10286,7 @@ namespace ranges {
1028610286
}
1028710287

1028810288
while (++_UFirst != _ULast) { // process one or two elements
10289-
auto _Prev = *_UFirst;
10289+
_Vty _Prev(*_UFirst);
1029010290
if (++_UFirst == _ULast) { // process last element
1029110291
if (_STD invoke(_Pred, _STD invoke(_Proj, _Prev), _STD invoke(_Proj, _Found.min))) {
1029210292
_Found.min = _STD move(_Prev);

tests/std/test.lst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ tests\GH_003840_tellg_when_reading_lf_file_in_text_mode
236236
tests\GH_003867_output_nan
237237
tests\GH_004023_mdspan_fwd_prod_overflow
238238
tests\GH_004040_container_nonmember_functions
239+
tests\GH_004108_some_ranges_algos_construct_wrong_type
239240
tests\GH_004109_iter_value_t_direct_initialization
240241
tests\GH_004129_conversion_in_new_numeric_algorithms
241242
tests\GH_004201_chrono_formatter
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_20_matrix.lst
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <algorithm>
5+
#include <cstddef>
6+
#include <ranges>
7+
8+
using namespace std;
9+
10+
namespace gh4108 {
11+
struct RRef {
12+
RRef(RRef&&) = delete;
13+
};
14+
15+
struct Val {
16+
Val(const RRef&);
17+
auto operator<=>(const Val&) const = default;
18+
};
19+
20+
struct I {
21+
using value_type = Val;
22+
using difference_type = ptrdiff_t;
23+
Val& operator*() const;
24+
I& operator++();
25+
I operator++(int);
26+
I& operator--();
27+
I operator--(int);
28+
bool operator==(const I&) const;
29+
friend RRef&& iter_move(const I&);
30+
};
31+
32+
// GH-4108 <algorithm>: ranges::inplace_merge accidentally constructed remove_cvref_t<iter_rvalue_reference_t<I>>
33+
void test_gh_4108() {
34+
ranges::inplace_merge(I{}, I{}, I{});
35+
}
36+
} // namespace gh4108
37+
38+
namespace gh4102 {
39+
struct Ref {
40+
Ref(const Ref&) = delete;
41+
auto operator<=>(const Ref&) const = default;
42+
};
43+
44+
struct Val {
45+
Val() = default;
46+
Val(const Ref&);
47+
auto operator<=>(const Val&) const = default;
48+
};
49+
50+
struct I {
51+
using value_type = Val;
52+
using difference_type = ptrdiff_t;
53+
const Ref& operator*() const;
54+
I& operator++();
55+
void operator++(int);
56+
bool operator==(const I&) const;
57+
};
58+
59+
// GH-4102 <algorithm>: ranges::minmax accidentally constructed remove_cvref_t<iter_reference_t<I>>
60+
void test_gh_4102() {
61+
[[maybe_unused]] auto result = ranges::minmax(ranges::subrange<I, I>{});
62+
}
63+
} // namespace gh4102

0 commit comments

Comments
 (0)