Skip to content

Commit eeee5c7

Browse files
hardening tests to libcxx/test/libcxx
1 parent 344183d commit eeee5c7

File tree

8 files changed

+123
-74
lines changed

8 files changed

+123
-74
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: std-at-least-c++26
10+
// UNSUPPORTED: libcpp-hardening-mode=none, no-exceptions
11+
12+
#include <ranges>
13+
#include <utility>
14+
15+
#include "check_assertion.h"
16+
#include "../types.h"
17+
18+
int main() {
19+
{
20+
//valueless by exception test constructor
21+
std::ranges::concat_view<ThrowOnCopyView> concatView_2;
22+
std::ranges::iterator_t<std::ranges::concat_view<ThrowOnCopyView>> it1;
23+
std::ranges::iterator_t<std::ranges::concat_view<ThrowOnCopyView>> it2;
24+
try {
25+
it1 = concatView_2.begin();
26+
} catch (...) {
27+
TEST_LIBCPP_ASSERT_FAILURE(
28+
[&] {
29+
it2 = it1;
30+
(void)it2;
31+
}(),
32+
"valueless by exception");
33+
}
34+
}
35+
36+
{
37+
//valueless by exception test operator==
38+
std::ranges::concat_view<ThrowOnCopyView> concatView_2;
39+
std::ranges::iterator_t<std::ranges::concat_view<ThrowOnCopyView>> it1;
40+
std::ranges::iterator_t<std::ranges::concat_view<ThrowOnCopyView>> it2;
41+
try {
42+
it1 = concatView_2.begin();
43+
} catch (...) {
44+
TEST_LIBCPP_ASSERT_FAILURE([&] { (void)(it1 == it2); }(), "valueless by exception");
45+
}
46+
}
47+
48+
{
49+
//valueless by exception test operator--
50+
std::ranges::concat_view<ThrowOnCopyView> concatView_2;
51+
std::ranges::iterator_t<std::ranges::concat_view<ThrowOnCopyView>> it1;
52+
try {
53+
it1 = concatView_2.begin();
54+
} catch (...) {
55+
TEST_LIBCPP_ASSERT_FAILURE([&] { (void)--*it1; }(), "valueless by exception");
56+
}
57+
}
58+
59+
{
60+
//valueless by exception test operator*
61+
std::ranges::concat_view<ThrowOnCopyView> concatView_2;
62+
std::ranges::iterator_t<std::ranges::concat_view<ThrowOnCopyView>> it1;
63+
try {
64+
it1 = concatView_2.begin();
65+
} catch (...) {
66+
TEST_LIBCPP_ASSERT_FAILURE([&] { (void)*it1; }(), "valueless by exception");
67+
}
68+
}
69+
70+
{
71+
//valueless by exception test operator++
72+
std::ranges::concat_view<ThrowOnCopyView> concatView_2;
73+
std::ranges::iterator_t<std::ranges::concat_view<ThrowOnCopyView>> it1;
74+
try {
75+
it1 = concatView_2.begin();
76+
} catch (...) {
77+
TEST_LIBCPP_ASSERT_FAILURE([&] { (void)++*it1; }(), "valueless by exception");
78+
}
79+
}
80+
81+
{
82+
//valueless by exception test operator+=
83+
std::ranges::concat_view<ThrowOnCopyView> concatView_2;
84+
std::ranges::iterator_t<std::ranges::concat_view<ThrowOnCopyView>> it1;
85+
try {
86+
it1 = concatView_2.begin();
87+
} catch (...) {
88+
TEST_LIBCPP_ASSERT_FAILURE([&] { (void)(it1 += 1); }(), "valueless by exception");
89+
}
90+
}
91+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef TEST_LIBCXX_RANGES_RANGE_ADAPTORS_RANGE_CONCAT_TYPES_H
10+
#define TEST_LIBCXX_RANGES_RANGE_ADAPTORS_RANGE_CONCAT_TYPES_H
11+
12+
#include <ranges>
13+
#include <utility>
14+
15+
int globalArray[8] = {0, 1, 2, 3, 4, 5, 6, 7};
16+
17+
struct ThrowOnCopyView : std::ranges::view_base {
18+
int start_;
19+
int* ptr_;
20+
constexpr explicit ThrowOnCopyView(int* ptr = globalArray, int start = 0) : start_(start), ptr_(ptr) {}
21+
constexpr ThrowOnCopyView(ThrowOnCopyView&&) = default;
22+
constexpr ThrowOnCopyView(const ThrowOnCopyView&) { throw 42; };
23+
constexpr ThrowOnCopyView& operator=(ThrowOnCopyView&&) = default;
24+
constexpr ThrowOnCopyView& operator=(const ThrowOnCopyView&) {
25+
throw 42;
26+
return *this;
27+
};
28+
constexpr int* begin() const { return ptr_ + start_; }
29+
constexpr int* end() const { return ptr_ + 8; }
30+
};
31+
32+
#endif // TEST_LIBCXX_RANGES_RANGE_ADAPTORS_CONCAT_FILTER_TYPES_H

libcxx/test/std/ranges/range.adaptors/range.concat/iterator/compare.pass.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <concepts>
1616
#include <utility>
1717
#include <__type_traits/maybe_const.h>
18-
1918
#include "test_iterators.h"
2019
#include "test_macros.h"
2120
#include "test_range.h"

libcxx/test/std/ranges/range.adaptors/range.concat/iterator/ctor.pass.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
// REQUIRES: has-unix-headers, std-at-least-c++26
10-
// UNSUPPORTED: libcpp-hardening-mode=none, no-exceptions
1110

1211
#include <ranges>
1312

@@ -78,23 +77,6 @@ constexpr bool test() {
7877
static_assert(std::default_initializable<std::ranges::iterator_t<std::ranges::concat_view<MoveOnlyView>>>);
7978
static_assert(!std::default_initializable<std::ranges::iterator_t<std::ranges::concat_view<IterNoDefaultInitView>>>);
8079

81-
{
82-
//valueless by exception test
83-
std::ranges::concat_view<ThrowOnCopyView> concatView_2;
84-
std::ranges::iterator_t<std::ranges::concat_view<ThrowOnCopyView>> it1;
85-
std::ranges::iterator_t<std::ranges::concat_view<ThrowOnCopyView>> it2;
86-
try {
87-
it1 = concatView_2.begin();
88-
} catch (...) {
89-
TEST_LIBCPP_ASSERT_FAILURE(
90-
[&] {
91-
it2 = it1;
92-
(void)it2;
93-
}(),
94-
"valueless by exception");
95-
}
96-
}
97-
9880
return true;
9981
}
10082

libcxx/test/std/ranges/range.adaptors/range.concat/iterator/decrement.pass.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
// REQUIRES: std-at-least-c++26
10-
// UNSUPPORTED: libcpp-hardening-mode=none, no-exceptions
1110

1211
#include <ranges>
1312

@@ -17,7 +16,6 @@
1716
#include <iterator>
1817
#include <utility>
1918
#include <vector>
20-
#include "check_assertion.h"
2119
#include "test_iterators.h"
2220
#include "test_macros.h"
2321
#include "../types.h"
@@ -83,17 +81,6 @@ constexpr void test() {
8381
assert(result == view.end());
8482
assert(it == (result - 1));
8583
}
86-
87-
{
88-
//valueless by exception test
89-
std::ranges::concat_view<ThrowOnCopyView> concatView_2;
90-
std::ranges::iterator_t<std::ranges::concat_view<ThrowOnCopyView>> it1;
91-
try {
92-
it1 = concatView_2.begin();
93-
} catch (...) {
94-
TEST_LIBCPP_ASSERT_FAILURE([&] { (void)--*it1; }(), "valueless by exception");
95-
}
96-
}
9784
}
9885

9986
int main(int, char**) {

libcxx/test/std/ranges/range.adaptors/range.concat/iterator/deref.pass.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
// REQUIRES: std-at-least-c++26
10-
// UNSUPPORTED: libcpp-hardening-mode=none, no-exceptions
1110

1211
#include <ranges>
1312

@@ -16,7 +15,6 @@
1615
#include <concepts>
1716
#include <cstddef>
1817
#include <utility>
19-
#include "check_assertion.h"
2018
#include "test_iterators.h"
2119
#include "test_macros.h"
2220
#include "../types.h"
@@ -38,17 +36,6 @@ constexpr void test() {
3836
int& result = *iter;
3937
ASSERT_SAME_TYPE(int&, decltype(*iter));
4038
assert(&result == array.data());
41-
42-
{
43-
//valueless by exception test
44-
std::ranges::concat_view<ThrowOnCopyView> concatView_2;
45-
std::ranges::iterator_t<std::ranges::concat_view<ThrowOnCopyView>> it1;
46-
try {
47-
it1 = concatView_2.begin();
48-
} catch (...) {
49-
TEST_LIBCPP_ASSERT_FAILURE([&] { (void)*it1; }(), "valueless by exception");
50-
}
51-
}
5239
}
5340

5441
constexpr bool tests() {

libcxx/test/std/ranges/range.adaptors/range.concat/iterator/increment.pass.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
// REQUIRES: std-at-least-c++26
10-
// UNSUPPORTED: libcpp-hardening-mode=none, no-exceptions
1110

1211
#include <ranges>
1312

@@ -63,17 +62,6 @@ constexpr void test() {
6362
++it;
6463
assert(*it == array[4]);
6564
}
66-
67-
{
68-
//valueless by exception test
69-
std::ranges::concat_view<ThrowOnCopyView> concatView_2;
70-
std::ranges::iterator_t<std::ranges::concat_view<ThrowOnCopyView>> it1;
71-
try {
72-
it1 = concatView_2.begin();
73-
} catch (...) {
74-
TEST_LIBCPP_ASSERT_FAILURE([&] { (void)++*it1; }(), "valueless by exception");
75-
}
76-
}
7765
}
7866

7967
constexpr bool tests() {

libcxx/test/std/ranges/range.adaptors/range.concat/types.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include <ranges>
1313
#include <utility>
1414

15-
int globalArray[8] = {0, 1, 2, 3, 4, 5, 6, 7};
16-
1715
struct TrackInitialization {
1816
constexpr explicit TrackInitialization(bool* moved, bool* copied) : moved_(moved), copied_(copied) {}
1917
constexpr TrackInitialization(TrackInitialization const& other) : moved_(other.moved_), copied_(other.copied_) {
@@ -43,19 +41,4 @@ struct minimal_view : std::ranges::view_base {
4341
decltype(base(std::declval<Sent>())) sent_;
4442
};
4543

46-
struct ThrowOnCopyView : std::ranges::view_base {
47-
int start_;
48-
int* ptr_;
49-
constexpr explicit ThrowOnCopyView(int* ptr = globalArray, int start = 0) : start_(start), ptr_(ptr) {}
50-
constexpr ThrowOnCopyView(ThrowOnCopyView&&) = default;
51-
constexpr ThrowOnCopyView(const ThrowOnCopyView&) { throw 42; };
52-
constexpr ThrowOnCopyView& operator=(ThrowOnCopyView&&) = default;
53-
constexpr ThrowOnCopyView& operator=(const ThrowOnCopyView&) {
54-
throw 42;
55-
return *this;
56-
};
57-
constexpr int* begin() const { return ptr_ + start_; }
58-
constexpr int* end() const { return ptr_ + 8; }
59-
};
60-
6144
#endif // TEST_STD_RANGES_RANGE_ADAPTORS_CONCAT_FILTER_TYPES_H

0 commit comments

Comments
 (0)