Skip to content

Commit be36f41

Browse files
committed
[libc++][NFC] Run two tests I'm about to modify a bunch under clang-format
1 parent 7492666 commit be36f41

File tree

2 files changed

+67
-70
lines changed

2 files changed

+67
-70
lines changed

libcxx/test/std/utilities/memory/specialized.algorithms/specialized.construct/construct_at.pass.cpp

Lines changed: 60 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -21,88 +21,83 @@
2121
#include "test_iterators.h"
2222

2323
struct Foo {
24-
constexpr Foo() { }
25-
constexpr Foo(int a, char b, double c) : a_(a), b_(b), c_(c) { }
26-
constexpr Foo(int a, char b, double c, int* count) : Foo(a, b, c) { *count += 1; }
27-
constexpr bool operator==(Foo const& other) const {
28-
return a_ == other.a_ && b_ == other.b_ && c_ == other.c_;
29-
}
24+
constexpr Foo() {}
25+
constexpr Foo(int a, char b, double c) : a_(a), b_(b), c_(c) {}
26+
constexpr Foo(int a, char b, double c, int* count) : Foo(a, b, c) { *count += 1; }
27+
constexpr bool operator==(Foo const& other) const { return a_ == other.a_ && b_ == other.b_ && c_ == other.c_; }
3028

3129
private:
32-
int a_;
33-
char b_;
34-
double c_;
30+
int a_;
31+
char b_;
32+
double c_;
3533
};
3634

3735
struct Counted {
38-
int& count_;
39-
constexpr Counted(int& count) : count_(count) { ++count; }
40-
constexpr Counted(Counted const& that) : count_(that.count_) { ++count_; }
41-
constexpr ~Counted() { --count_; }
36+
int& count_;
37+
constexpr Counted(int& count) : count_(count) { ++count; }
38+
constexpr Counted(Counted const& that) : count_(that.count_) { ++count_; }
39+
constexpr ~Counted() { --count_; }
4240
};
4341

44-
constexpr bool test()
45-
{
46-
{
47-
int i = 99;
48-
int* res = std::construct_at(&i);
49-
assert(res == &i);
50-
assert(*res == 0);
51-
}
52-
53-
{
54-
int i = 0;
55-
int* res = std::construct_at(&i, 42);
56-
assert(res == &i);
57-
assert(*res == 42);
58-
}
59-
60-
{
61-
Foo foo = {};
62-
int count = 0;
63-
Foo* res = std::construct_at(&foo, 42, 'x', 123.89, &count);
64-
assert(res == &foo);
65-
assert(*res == Foo(42, 'x', 123.89));
66-
assert(count == 1);
67-
}
68-
69-
{
70-
std::allocator<Counted> a;
71-
Counted* p = a.allocate(2);
72-
int count = 0;
73-
std::construct_at(p, count);
74-
assert(count == 1);
75-
std::construct_at(p+1, count);
76-
assert(count == 2);
77-
(p+1)->~Counted();
78-
assert(count == 1);
79-
p->~Counted();
80-
assert(count == 0);
81-
a.deallocate(p, 2);
82-
}
83-
84-
return true;
42+
constexpr bool test() {
43+
{
44+
int i = 99;
45+
int* res = std::construct_at(&i);
46+
assert(res == &i);
47+
assert(*res == 0);
48+
}
49+
50+
{
51+
int i = 0;
52+
int* res = std::construct_at(&i, 42);
53+
assert(res == &i);
54+
assert(*res == 42);
55+
}
56+
57+
{
58+
Foo foo = {};
59+
int count = 0;
60+
Foo* res = std::construct_at(&foo, 42, 'x', 123.89, &count);
61+
assert(res == &foo);
62+
assert(*res == Foo(42, 'x', 123.89));
63+
assert(count == 1);
64+
}
65+
66+
{
67+
std::allocator<Counted> a;
68+
Counted* p = a.allocate(2);
69+
int count = 0;
70+
std::construct_at(p, count);
71+
assert(count == 1);
72+
std::construct_at(p + 1, count);
73+
assert(count == 2);
74+
(p + 1)->~Counted();
75+
assert(count == 1);
76+
p->~Counted();
77+
assert(count == 0);
78+
a.deallocate(p, 2);
79+
}
80+
81+
return true;
8582
}
8683

87-
template <class ...Args>
88-
constexpr bool can_construct_at = requires {
89-
std::construct_at(std::declval<Args>()...);
90-
};
84+
template <class... Args>
85+
constexpr bool can_construct_at = requires { std::construct_at(std::declval<Args>()...); };
9186

9287
// Check that SFINAE works.
93-
static_assert( can_construct_at<int*, int>);
94-
static_assert( can_construct_at<Foo*, int, char, double>);
88+
static_assert(can_construct_at<int*, int>);
89+
static_assert(can_construct_at<Foo*, int, char, double>);
9590
static_assert(!can_construct_at<Foo*, int, char>);
9691
static_assert(!can_construct_at<Foo*, int, char, double, int>);
9792
static_assert(!can_construct_at<std::nullptr_t, int, char, double>);
9893
static_assert(!can_construct_at<int*, int, char, double>);
9994
static_assert(!can_construct_at<contiguous_iterator<Foo*>, int, char, double>);
10095
// Can't construct function pointers.
101-
static_assert(!can_construct_at<int(*)()>);
102-
static_assert(!can_construct_at<int(*)(), std::nullptr_t>);
96+
static_assert(!can_construct_at<int (*)()>);
97+
static_assert(!can_construct_at<int (*)(), std::nullptr_t>);
10398

10499
int main(int, char**) {
105-
test();
106-
static_assert(test());
107-
return 0;
100+
test();
101+
static_assert(test());
102+
return 0;
108103
}

libcxx/test/std/utilities/memory/specialized.algorithms/specialized.construct/ranges_construct_at.pass.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ constexpr bool test() {
8585
{
8686
std::allocator<Counted> alloc;
8787
Counted* out = alloc.allocate(2);
88-
int count = 0;
88+
int count = 0;
8989

9090
Counted* result = std::ranges::construct_at(out, count);
9191
assert(result == out);
@@ -104,20 +104,22 @@ constexpr bool test() {
104104

105105
constexpr bool can_construct_at(auto&&... args)
106106
requires requires { std::ranges::construct_at(decltype(args)(args)...); }
107-
{ return true; }
107+
{
108+
return true;
109+
}
108110

109111
constexpr bool can_construct_at(auto&&...) { return false; }
110112

111113
// Check that SFINAE works.
112-
static_assert( can_construct_at((Foo*)nullptr, 1, 2));
114+
static_assert(can_construct_at((Foo*)nullptr, 1, 2));
113115
static_assert(!can_construct_at((Foo*)nullptr, 1));
114116
static_assert(!can_construct_at((Foo*)nullptr, 1, 2, 3));
115117
static_assert(!can_construct_at(nullptr, 1, 2));
116118
static_assert(!can_construct_at((int*)nullptr, 1, 2));
117119
static_assert(!can_construct_at(contiguous_iterator<Foo*>(), 1, 2));
118120
// Can't construct function pointers.
119-
static_assert(!can_construct_at((int(*)())nullptr));
120-
static_assert(!can_construct_at((int(*)())nullptr, nullptr));
121+
static_assert(!can_construct_at((int (*)()) nullptr));
122+
static_assert(!can_construct_at((int (*)()) nullptr, nullptr));
121123
// TODO(varconst): check that array types work once D114649 implementing LWG3639 lands.
122124

123125
int main(int, char**) {

0 commit comments

Comments
 (0)