Skip to content

Commit 7c9de07

Browse files
committed
add drop_only tests for arc/rc
1 parent 250b13b commit 7c9de07

File tree

3 files changed

+51
-10
lines changed

3 files changed

+51
-10
lines changed

libsafecxx/single-header/std2.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,10 @@ arc
798798
T const^ operator->(self const^) noexcept safe {
799799
return ^*self->p_->data_.get();
800800
}
801+
802+
T const^ operator*(self const^) noexcept safe {
803+
return ^*self->p_->data_.get();
804+
}
801805
};
802806

803807
////////////////////////////////////////////////////////////////////////////////

libsafecxx/test/arc_test.cxx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,44 @@
33
#include <std2.h>
44
#include "lightweight_test.h"
55

6+
struct anon_callable/(a, b, c)
7+
{
8+
std2::string_view/c sv_;
9+
int^/a x_;
10+
int const^/b y_;
11+
12+
anon_callable(
13+
std2::string_view/c sv,
14+
int^/a x,
15+
int const^/b y) safe
16+
: sv_(sv)
17+
, x_(x)
18+
, y_(y)
19+
{
20+
}
21+
22+
[[unsafe::drop_only(a, b)]]
23+
~anon_callable() = default;
24+
25+
void operator()(self const^) safe
26+
{
27+
self->sv_;
28+
self->x_;
29+
self->y_;
30+
}
31+
};
32+
33+
void functor_test() safe
34+
{
35+
std2::string_view sv = "hello, world!"sv2;
36+
37+
int a = 1234;
38+
int const b = 4321;
39+
40+
anon_callable f(sv, ^a, b);
41+
f();
42+
}
43+
644
void drop_only() safe
745
{
846
{
@@ -11,10 +49,10 @@ void drop_only() safe
1149
std2::string s("hello, world!");
1250

1351
// TODO: re-enable this test once we get pointer variance working
14-
// p = std2::arc(s.str());
15-
// assert_true(*p == "hello, world!"sv2);
52+
p = std2::arc(s.str());
53+
REQUIRE_EQ(*p, "hello, world!"sv2);
1654
}
1755
}
1856
}
1957

20-
TEST_MAIN(drop_only)
58+
TEST_MAIN(functor_test, drop_only)

libsafecxx/test/rc_test.cxx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@ void drop_only() safe
3737
std2::string s("hello, world!");
3838

3939
// TODO: re-enable this test once we get pointer variance working
40-
// p = std2::rc(s.str());
41-
// REQUIRE(*p == "hello, world!"sv2);
40+
p = std2::rc(s.str());
41+
REQUIRE(*p == "hello, world!"sv2);
4242
}
4343
}
4444
}
4545

46-
int main() safe
47-
{
48-
rc_constructor();
49-
drop_only();
50-
}
46+
TEST_MAIN(
47+
rc_constructor,
48+
drop_only
49+
)

0 commit comments

Comments
 (0)