Skip to content

Commit

Permalink
Address AlexG's other potential occurrences
Browse files Browse the repository at this point in the history
  • Loading branch information
CaseyCarter committed Oct 26, 2021
1 parent 76cad46 commit f847e92
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 16 deletions.
12 changes: 12 additions & 0 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -3777,7 +3777,13 @@ namespace ranges {
return *this;
}

#if defined(__clang__) || defined(__EDG__) // TRANSITION, DevCom-1559808
auto [_Begin, _End] = _RANGES search(subrange{_Current, _Last}, _Parent->_Pattern);
#else // ^^^ no workaround / workaround vvv
auto _Match = _RANGES search(subrange{_Current, _Last}, _Parent->_Pattern);
auto _Begin = _Match.begin();
auto _End = _Match.end();
#endif // TRANSITION, DevCom-1559808
if (_Begin != _Last && _RANGES empty(_Parent->_Pattern)) {
++_Begin;
++_End;
Expand Down Expand Up @@ -3823,7 +3829,13 @@ namespace ranges {

constexpr subrange<iterator_t<_Vw>> _Find_next(iterator_t<_Vw> _It) {
const auto _Last = _RANGES end(_Range);
#if defined(__clang__) || defined(__EDG__) // TRANSITION, DevCom-1559808
auto [_Begin, _End] = _RANGES search(subrange{_It, _Last}, _Pattern);
#else // ^^^ no workaround / workaround vvv
auto _Match = _RANGES search(subrange{_It, _Last}, _Pattern);
auto _Begin = _Match.begin();
auto _End = _Match.end();
#endif // TRANSITION, DevCom-1559808
if (_Begin != _Last && _RANGES empty(_Pattern)) {
++_Begin;
++_End;
Expand Down
21 changes: 21 additions & 0 deletions tests/std/tests/P0896R4_ranges_alg_find_end/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <ranges>
#include <span>
#include <utility>
#include <vector>

#include <range_algorithm_support.hpp>

Expand Down Expand Up @@ -71,9 +72,29 @@ constexpr void smoke_test() {
}
}

constexpr void test_1559808() {
// Regression test for DevCom-1559808, an interaction between vector and the
// use of structured bindings in the constexpr evaluator.

std::vector<int> haystack(33, 42), needle(8, 42); // No particular significance to any numbers in this function
using size_type = std::vector<int>::size_type;

auto result = ranges::find_end(haystack, needle);
assert(static_cast<size_type>(result.begin() - haystack.begin()) == haystack.size() - needle.size());
assert(result.end() == haystack.end());

needle.assign(6, 1729);
result = ranges::find_end(haystack, needle);
assert(result.begin() == haystack.end());
assert(result.end() == haystack.end());
}

int main() {
STATIC_ASSERT((smoke_test(), true));
smoke_test();

STATIC_ASSERT((test_1559808(), true));
test_1559808();
}

#ifndef _PREFAST_ // TRANSITION, GH-1030
Expand Down
20 changes: 20 additions & 0 deletions tests/std/tests/P0896R4_ranges_alg_search/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <ranges>
#include <span>
#include <utility>
#include <vector>

#include <range_algorithm_support.hpp>

Expand Down Expand Up @@ -168,8 +169,27 @@ constexpr bool run_tests() {
return true;
}

constexpr void test_1559808() {
// Regression test for DevCom-1559808, an interaction between vector and the
// use of structured bindings in the constexpr evaluator.

std::vector<int> haystack(33, 42), needle(8, 42); // No particular significance to any numbers in this function

auto result = ranges::search(haystack, needle);
assert(result.begin() == haystack.begin());
assert(result.end() == haystack.begin() + ranges::ssize(needle));

needle.assign(6, 1729);
result = ranges::search(haystack, needle);
assert(result.begin() == haystack.end());
assert(result.end() == haystack.end());
}

int main() {
STATIC_ASSERT(run_tests());
run_tests();

STATIC_ASSERT((test_1559808(), true));
test_1559808();
}
#endif // TEST_EVERYTHING
20 changes: 4 additions & 16 deletions tests/std/tests/P0896R4_ranges_alg_sort/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,11 @@ struct instantiator {

constexpr void test_1559808() {
// Regression test for DevCom-1559808, a bad interaction between constexpr vector and the use of structured bindings
// in the implemenation of ranges::sort.
// in the implementation of ranges::sort.

auto collatz = [](int n) {
vector<int> vec = {n};
while (n != 1) {
if (n % 2 == 0) {
n /= 2;
} else {
n = n * 3 + 1;
}
vec.push_back(n);
}
ranges::sort(vec);
return vec.back();
};

assert(collatz(27) == 9232);
vector<int> vec(33, 42); // NB: 33 > std::_ISORT_MAX
ranges::sort(vec);
assert(vec.back() == 42);
}

int main() {
Expand Down
26 changes: 26 additions & 0 deletions tests/std/tests/P0896R4_views_split/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <system_error>
#include <type_traits>
#include <utility>
#include <vector>

#include <range_algorithm_support.hpp>
using namespace std;
Expand Down Expand Up @@ -320,7 +321,32 @@ constexpr bool instantiation_test() {
return true;
}

constexpr bool test_1559808() {
// Regression test for DevCom-1559808, an interaction between vector and the
// use of structured bindings in the constexpr evaluator.

vector<char> letters{'T', 'h', 'i', 's', ' ', 'i', 's', ' ', 'a', ' ', 't', 'e', 's', 't'};
auto r = views::split(letters, ' ');
auto i = r.begin();
assert(*(*i).begin() == 'T');
++i;
assert(*(*i).begin() == 'i');
++i;
assert(*(*i).begin() == 'a');
++i;
assert(*(*i).begin() == 't');
++i;
assert(i == r.end());

return true;
}

int main() {
STATIC_ASSERT(instantiation_test());
instantiation_test();

#if defined(__clang__) || defined(__EDG__) // TRANSITION, DevDiv-1516290
STATIC_ASSERT(test_1559808());
#endif // TRANSITION, DevDiv-1516290
test_1559808();
}

0 comments on commit f847e92

Please sign in to comment.