
This patch hardens the "test iterators" we use to test algorithms by ensuring that they don't get double-moved. As a result of this hardening, the tests started reporting multiple failures where we would double-move iterators, which are being fixed in this patch. In particular: - Fixed a double-move in pstl.partition - Add coverage for begin()/end() in subrange tests - Fix tests for ranges::ends_with and ranges::contains, which were incorrectly calling begin() twice on the same subrange containing non-copyable input iterators. Fixes #100709
44 lines
1.2 KiB
C++
44 lines
1.2 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef TEST_SUPPORT_DOUBLE_MOVE_TRACKER_H
|
|
#define TEST_SUPPORT_DOUBLE_MOVE_TRACKER_H
|
|
|
|
#include <cassert>
|
|
|
|
#include "test_macros.h"
|
|
|
|
namespace support {
|
|
|
|
struct double_move_tracker {
|
|
TEST_CONSTEXPR double_move_tracker() : moved_from_(false) {}
|
|
|
|
double_move_tracker(double_move_tracker const&) = default;
|
|
|
|
TEST_CONSTEXPR_CXX14 double_move_tracker(double_move_tracker&& other) : moved_from_(false) {
|
|
assert(!other.moved_from_);
|
|
other.moved_from_ = true;
|
|
}
|
|
|
|
double_move_tracker& operator=(double_move_tracker const&) = default;
|
|
|
|
TEST_CONSTEXPR_CXX14 double_move_tracker& operator=(double_move_tracker&& other) {
|
|
assert(!other.moved_from_);
|
|
other.moved_from_ = true;
|
|
moved_from_ = false;
|
|
return *this;
|
|
}
|
|
|
|
private:
|
|
bool moved_from_;
|
|
};
|
|
|
|
} // namespace support
|
|
|
|
#endif // TEST_SUPPORT_DOUBLE_MOVE_TRACKER_H
|