Skip to content

Commit 730bca0

Browse files
committed
Remove even more redundant preprocessor conditions in tests
1 parent ba1dd83 commit 730bca0

6 files changed

Lines changed: 0 additions & 45 deletions

File tree

  • tests/std/tests
    • P0122R7_span
    • P0355R7_calendars_and_time_zones_clocks
    • P0355R7_calendars_and_time_zones_time_zones
    • P0768R1_spaceship_operator
    • P0784R7_library_machinery
    • P0784R7_library_support_for_more_constexpr_containers

tests/std/tests/P0122R7_span/test.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
#include <span>
1010
#include <type_traits>
1111
#include <utility>
12-
13-
#if _HAS_CXX20
1412
#include <ranges>
15-
#endif // _HAS_CXX20
1613

1714
using namespace std;
1815

@@ -74,10 +71,8 @@ static_assert(is_same_v<span<const int>::reverse_iterator, reverse_iterator<span
7471
static_assert(is_same_v<iterator_traits<span<const int, 3>::iterator>::pointer, const int*>);
7572
static_assert(is_same_v<span<const int, 3>::reverse_iterator, reverse_iterator<span<const int, 3>::iterator>>);
7673

77-
#if _HAS_CXX20
7874
static_assert(ranges::enable_borrowed_range<span<int>>);
7975
static_assert(ranges::enable_borrowed_range<span<int, 3>>);
80-
#endif // _HAS_CXX20
8176

8277
// N4901 [span.overview]/3
8378
static_assert(is_trivially_copyable_v<span<int>>);
@@ -145,12 +140,10 @@ struct BasicRange {
145140
}
146141
};
147142

148-
#if _HAS_CXX20
149143
namespace std::ranges {
150144
template <typename T, bool Borrowed>
151145
inline constexpr bool enable_borrowed_range<BasicRange<T, Borrowed>> = Borrowed;
152146
}
153-
#endif // _HAS_CXX20
154147

155148
using ContiguousSizedRange = BasicRange<int>;
156149

@@ -247,7 +240,6 @@ constexpr bool test() {
247240
static_assert(is_same_v<decltype(span{as_const(arr), 3}), span<const int>>);
248241
static_assert(is_same_v<decltype(span{cbegin(arr), 3}), span<const int>>);
249242

250-
#if _HAS_CXX20
251243
static_assert(is_nothrow_constructible_v<span<int>, array<int, 3>::iterator, size_t>); // strengthened
252244
static_assert(!is_constructible_v<span<int>, array<int, 3>::const_iterator, size_t>);
253245
static_assert(!is_constructible_v<span<int>, array<double, 3>::iterator, size_t>);
@@ -292,7 +284,6 @@ constexpr bool test() {
292284

293285
static_assert(is_same_v<decltype(span{stl.begin(), 3}), span<int>>);
294286
static_assert(is_same_v<decltype(span{stl.cbegin(), 3}), span<const int>>);
295-
#endif // _HAS_CXX20
296287
}
297288

298289
{
@@ -351,7 +342,6 @@ constexpr bool test() {
351342
static_assert(is_same_v<decltype(span{begin(arr), end(arr)}), span<int>>);
352343
static_assert(is_same_v<decltype(span{cbegin(arr), cend(arr)}), span<const int>>);
353344

354-
#if _HAS_CXX20
355345
static_assert(is_nothrow_constructible_v<span<int>, int*, const int*>); // strengthened
356346

357347
static_assert(is_nothrow_constructible_v<span<int, 3>, int*, const int*>); // strengthened
@@ -456,7 +446,6 @@ constexpr bool test() {
456446
static_assert(is_same_v<decltype(span{stl.begin(), stl.cend()}), span<int>>);
457447
static_assert(is_same_v<decltype(span{stl.cbegin(), stl.end()}), span<const int>>);
458448
static_assert(is_same_v<decltype(span{stl.cbegin(), stl.cend()}), span<const int>>);
459-
#endif // _HAS_CXX20
460449
}
461450

462451
{
@@ -619,7 +608,6 @@ constexpr bool test() {
619608
FunctionTakingSpan<const int>(user_range);
620609
FunctionTakingSpan<const int>(as_const(user_range));
621610

622-
#if _HAS_CXX20
623611
static_assert(!is_constructible_v<span<int>, ContiguousSizedRange>);
624612
static_assert(!is_constructible_v<span<int, 3>, ContiguousSizedRange>);
625613
static_assert(is_constructible_v<span<int>, BorrowedContiguousSizedRange>);
@@ -654,7 +642,6 @@ constexpr bool test() {
654642

655643
static_assert(is_same_v<decltype(span{user_range}), span<int>>);
656644
static_assert(is_same_v<decltype(span{as_const(user_range)}), span<const int>>);
657-
#endif // _HAS_CXX20
658645
}
659646

660647
{

tests/std/tests/P0355R7_calendars_and_time_zones_clocks/test.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ constexpr bool test_leap_second() {
154154
static_assert(noexcept(equal >= leap));
155155
static_assert(noexcept(leap >= equal));
156156

157-
#if _HAS_CXX20
158157
static_assert(is_eq(leap <=> equal));
159158
static_assert(is_lt(leap <=> larger));
160159
static_assert(is_gt(leap <=> smaller));
@@ -172,7 +171,6 @@ constexpr bool test_leap_second() {
172171
static_assert(is_lteq(leap <=> leap_second{equal, true, 0s}));
173172
static_assert(is_gteq(leap <=> leap_second{equal, true, 0s}));
174173
static_assert(noexcept(leap <=> leap_second{equal, true, 0s}));
175-
#endif // _HAS_CXX20
176174

177175
static_assert(noexcept(leap.date()));
178176
static_assert(noexcept(leap.value()));

tests/std/tests/P0355R7_calendars_and_time_zones_time_zones/test.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,18 @@ void timezone_names_test() {
114114
const time_zone tz3{_Secret_time_zone_construct_tag{}, "Later"};
115115
assert(tz1 == tz2);
116116
assert(tz1 != tz3);
117-
#if _HAS_CXX20
118117
assert(tz1 <=> tz2 == strong_ordering::equal);
119118
assert(tz1 <=> tz3 == strong_ordering::less);
120119
assert(tz3 <=> tz1 == strong_ordering::greater);
121-
#endif // _HAS_CXX20
122120

123121
const time_zone_link link1{_Secret_time_zone_link_construct_tag{}, "Earlier", "Target"};
124122
const time_zone_link link2{_Secret_time_zone_link_construct_tag{}, "Earlier", "Is"};
125123
const time_zone_link link3{_Secret_time_zone_link_construct_tag{}, "Later", "Ignored"};
126124
assert(link1 == link2);
127125
assert(link1 != link3);
128-
#if _HAS_CXX20
129126
assert(link1 <=> link2 == strong_ordering::equal);
130127
assert(link1 <=> link3 == strong_ordering::less);
131128
assert(link3 <=> link1 == strong_ordering::greater);
132-
#endif // _HAS_CXX20
133129

134130
try {
135131
// ensure locate_zone returns time_zone with given name

tests/std/tests/P0768R1_spaceship_operator/test.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ static_assert(test_common_type<std::strong_ordering, std::partial_ordering>());
151151
static_assert(test_common_type<std::strong_ordering, std::weak_ordering>());
152152
static_assert(test_common_type<std::strong_ordering, std::strong_ordering>());
153153

154-
#if _HAS_CXX20
155154
constexpr auto my_cmp_three_way = [](const auto& left, const auto& right) { return left <=> right; };
156155

157156
template <class Left, class Right>
@@ -217,7 +216,6 @@ void test_algorithm() {
217216
assert((test_algorithm2<Ty1, Ty2>()));
218217
assert((test_algorithm2<Ty2, Ty1>()));
219218
}
220-
#endif // _HAS_CXX20
221219

222220
int main() {
223221
static_assert(test_orderings());
@@ -226,12 +224,10 @@ int main() {
226224
static_assert(test_spaceships());
227225
test_spaceships();
228226

229-
#if _HAS_CXX20
230227
test_algorithm<int>();
231228
test_algorithm<char>();
232229
test_algorithm<unsigned char>();
233230
test_algorithm<int, char>();
234231
test_algorithm<int, unsigned char>();
235232
test_algorithm<char, unsigned char>();
236-
#endif // _HAS_CXX20
237233
}

tests/std/tests/P0784R7_library_machinery/test.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ constexpr bool test() {
120120
}
121121
}
122122

123-
#if _HAS_CXX20
124123
{ // _Move_backward_common
125124
int_wrapper_move input[] = {1, 2, 3, 4};
126125
int_wrapper_move output[4] = {5, 6, 7, 8};
@@ -133,7 +132,6 @@ constexpr bool test() {
133132
assert(equal(begin(input), end(input), begin(expected_after_move), end(expected_after_move)));
134133
}
135134
}
136-
#endif // _HAS_CXX20
137135

138136
{ // _Uninitialized_move_unchecked
139137
int_wrapper_move input[] = {1, 2, 3, 4};

tests/std/tests/P0784R7_library_support_for_more_constexpr_containers/test.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
using namespace std;
1818

19-
#if _HAS_CXX20
2019
template <class Ty, class... Types>
2120
concept can_std_construct_at = requires(Ty* ptr, Types&&... args) { construct_at(ptr, forward<Types>(args)...); };
2221

@@ -77,7 +76,6 @@ template <class T>
7776
constexpr bool destroy_at_noexcept() {
7877
return noexcept(destroy_at(declval<T*>()));
7978
}
80-
#endif // _HAS_CXX20
8179

8280
static_assert(can_construct_at<int>);
8381
static_assert(can_construct_at<int, int>);
@@ -164,10 +162,8 @@ struct throwing_dtor {
164162
static_assert(destroy_at_noexcept<throwing_dtor>());
165163
static_assert(destroy_at_noexcept<throwing_dtor[42]>());
166164

167-
#if _HAS_CXX20
168165
static_assert(!can_ranges_destroy_at<throwing_dtor>);
169166
static_assert(!can_ranges_destroy_at<throwing_dtor[42]>);
170-
#endif // _HAS_CXX20
171167

172168
template <class Ty>
173169
void test_runtime(const Ty& val) {
@@ -178,13 +174,11 @@ void test_runtime(const Ty& val) {
178174
assert(*asPtrTy == val);
179175
destroy_at(asPtrTy);
180176

181-
#if _HAS_CXX20
182177
// test ranges:
183178
memset(storage, 42, sizeof(Ty));
184179
assert(asPtrTy == ranges::construct_at(asPtrTy, val));
185180
assert(*asPtrTy == val);
186181
ranges::destroy_at(asPtrTy);
187-
#endif // _HAS_CXX20
188182
}
189183

190184
template <class T>
@@ -201,13 +195,11 @@ void test_array(const T& val) {
201195

202196
destroy_at(reinterpret_cast<T(*)[N]>(ptr));
203197

204-
#if _HAS_CXX20
205198
for (auto i = 0; i < N; ++i) {
206199
ranges::construct_at(ptr + i, val);
207200
}
208201

209202
ranges::destroy_at(reinterpret_cast<T(*)[N]>(ptr));
210-
#endif // _HAS_CXX20
211203
}
212204

213205
template <class T>
@@ -227,11 +219,9 @@ constexpr void test_compiletime() {
227219
assert(s.object == 42);
228220
destroy_at(&s.object);
229221

230-
#if _HAS_CXX20
231222
ranges::construct_at(&s.object, 1729);
232223
assert(s.object == 1729);
233224
ranges::destroy_at(&s.object);
234-
#endif // _HAS_CXX20
235225
}
236226

237227
struct nontrivial {
@@ -247,11 +237,9 @@ constexpr void test_compiletime() {
247237
assert(s.object.x == 42);
248238
destroy_at(&s.object);
249239

250-
#if _HAS_CXX20
251240
ranges::construct_at(&s.object, 1729);
252241
assert(s.object.x == 1729);
253242
ranges::destroy_at(&s.object);
254-
#endif // _HAS_CXX20
255243
}
256244
}
257245
static_assert((test_compiletime(), true));
@@ -295,7 +283,6 @@ constexpr void test_compiletime_destroy_variants() {
295283
destroy(a, a + 10);
296284
alloc.deallocate(a, 10);
297285
}
298-
#if _HAS_CXX20
299286
{
300287
allocator<A<int>> alloc{};
301288
A<int>* a = alloc.allocate(10);
@@ -334,7 +321,6 @@ constexpr void test_compiletime_destroy_variants() {
334321
ranges::destroy(s);
335322
alloc.deallocate(a, 10);
336323
}
337-
#endif // _HAS_CXX20
338324
{
339325
allocator<A<int>> alloc{};
340326
A<int>* a = alloc.allocate(10);
@@ -353,7 +339,6 @@ constexpr void test_compiletime_destroy_variants() {
353339
destroy_n(a, 10);
354340
alloc.deallocate(a, 10);
355341
}
356-
#if _HAS_CXX20
357342
{
358343
allocator<A<int>> alloc{};
359344
A<int>* a = alloc.allocate(10);
@@ -372,7 +357,6 @@ constexpr void test_compiletime_destroy_variants() {
372357
ranges::destroy_n(a, 10);
373358
alloc.deallocate(a, 10);
374359
}
375-
#endif // _HAS_CXX20
376360
}
377361
static_assert((test_compiletime_destroy_variants(), true));
378362

@@ -519,7 +503,6 @@ constexpr void test_compiletime_operators() {
519503
}
520504
static_assert((test_compiletime_operators(), true));
521505

522-
#if _HAS_CXX20
523506
// Also test LWG-3888 Most ranges uninitialized memory algorithms are underconstrained
524507
template <class Rng>
525508
concept CanUninitializedDefaultConstruct = requires(Rng& r) { ranges::uninitialized_default_construct(r); };
@@ -623,7 +606,6 @@ static_assert(CanDestroyN<char*>);
623606
static_assert(!CanDestroyN<const char*>);
624607
static_assert(!CanDestroyN<volatile char*>);
625608
static_assert(!CanDestroyN<const volatile char*>);
626-
#endif // _HAS_CXX20
627609

628610
int main() {
629611
test_runtime(1234);
@@ -636,10 +618,8 @@ int main() {
636618
construct_at(ptr);
637619
ptr->destroy();
638620

639-
#if _HAS_CXX20
640621
ranges::construct_at(ptr);
641622
ptr->destroy();
642-
#endif // _HAS_CXX20
643623
}
644624

645625
test_array(1234);

0 commit comments

Comments
 (0)