llvm-project/libcxx/test/std/containers/iterator.rel_ops.compile.pass.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

142 lines
3.7 KiB
C++
Raw Normal View History

//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
[libc++] Use named Lit features to flag back-deployment XFAILs Instead of writing something like `XFAIL: use_system_cxx_lib && target=...` to XFAIL back-deployment tests, introduce named Lit features like `availability-shared_mutex-missing` to represent those. This makes the XFAIL annotations leaner, and solves the problem of XFAIL comments potentially getting out of sync. This would also make it easier for another vendor to add their own annotations to the test suite by simply changing how the feature is defined for their OS releases, instead of having to modify hundreds of tests to add repetitive annotations. This doesn't touch *all* annotations -- only annotations that were widely duplicated are given named features (e.g. when filesystem or shared_mutex were introduced). I still think it probably doesn't make sense to have a named feature for every single fix we make to the dylib. This is in essence a revert of 2659663, but since then the test suite has changed significantly. Back when I did 2659663, the configuration files we have for the test suite right now were being bootstrapped and it wasn't clear how to provide these features for back-deployment in that context. Since then, we have a streamlined way of defining these features in `features.py` and that doesn't impact the ability for a configuration file to stay minimal. The original motivation for this change was that I am about to propose a change that would touch essentially all XFAIL annotations for back-deployment in the test suite, and this greatly reduces the number of lines changed by that upcoming change, in addition to making the test suite generally better. Differential Revision: https://reviews.llvm.org/D146359
2023-03-18 10:05:19 -04:00
// XFAIL: availability-filesystem-missing
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
// Make sure the various containers' iterators are not broken by the use of `std::rel_ops`.
#include <utility> // for std::rel_ops
#include <array>
#include <deque>
#include <filesystem>
#include <forward_list>
#include <list>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "test_macros.h"
#if TEST_STD_VER >= 17
#include <string_view>
#endif
#if TEST_STD_VER >= 20
#include <span>
#endif
using namespace std::rel_ops;
template<class It, class ConstIt>
void test_eq(It it, ConstIt cit) {
(void)(it == it);
(void)(it != it);
(void)(it == cit);
(void)(it != cit);
(void)(cit == it);
(void)(cit != it);
(void)(cit == cit);
(void)(cit != cit);
}
template<class It, class ConstIt>
void test_lt(It it, ConstIt cit) {
(void)(it < it);
(void)(it <= it);
(void)(it > it);
(void)(it >= it);
(void)(it < cit);
(void)(it <= cit);
(void)(it > cit);
(void)(it >= cit);
(void)(cit < it);
(void)(cit <= it);
(void)(cit > it);
(void)(cit >= it);
(void)(cit < cit);
(void)(cit <= cit);
(void)(cit > cit);
(void)(cit >= cit);
// Test subtraction too, even though std::rel_ops shouldn't affect it.
(void)(it - it);
(void)(it - cit);
(void)(cit - it);
(void)(cit - cit);
}
template<class Container>
void test_forward() {
// There is no need to distinguish "forward" from "bidirectional."
// libc++ already can't handle `c.rbegin() >= c.rbegin()` in the
// presence of std::rel_ops, and neither can Microsoft nor libstdc++.
Container c;
typename Container::iterator it = c.begin();
typename Container::const_iterator cit = c.begin();
test_eq(it, cit);
}
template<class Container>
void test_random_access() {
Container c;
typename Container::iterator it = c.begin();
typename Container::const_iterator cit = c.begin();
test_eq(it, cit);
test_lt(it, cit);
}
template void test_random_access<std::array<int, 10> >();
template void test_random_access<std::deque<int> >();
template void test_forward<std::forward_list<int> >();
template void test_forward<std::list<int> >();
template void test_forward<std::map<int, int> >();
template void test_forward<std::multimap<int, int> >();
template void test_forward<std::multiset<int> >();
template void test_forward<std::set<int> >();
template void test_random_access<std::string>();
template void test_forward<std::unordered_map<int, int> >();
template void test_forward<std::unordered_multimap<int, int> >();
template void test_forward<std::unordered_multiset<int> >();
template void test_forward<std::unordered_set<int> >();
template void test_random_access<std::vector<int> >();
#if TEST_STD_VER >= 17
void test_directory_iterators() {
#ifndef TEST_HAS_NO_FILESYSTEM
std::filesystem::directory_iterator it;
test_eq(it, it);
std::filesystem::recursive_directory_iterator rdit;
test_eq(rdit, rdit);
#endif
}
template void test_forward<std::filesystem::path>();
#endif
#if TEST_STD_VER >= 17
template void test_random_access<std::string_view>();
#endif
#if TEST_STD_VER >= 20
void test_span() {
std::span<int> c;
std::span<int>::iterator it = c.begin(); // span has no const_iterator
test_eq(it, it);
test_lt(it, it);
}
#endif