File tree Expand file tree Collapse file tree 3 files changed +76
-0
lines changed Expand file tree Collapse file tree 3 files changed +76
-0
lines changed Original file line number Diff line number Diff line change @@ -28,3 +28,8 @@ module MsvcUseVecIt {
28
28
requires cplusplus
29
29
export *
30
30
}
31
+
32
+ module StdUniquePtr {
33
+ header "std-unique-ptr.h"
34
+ requires cplusplus
35
+ }
Original file line number Diff line number Diff line change
1
+ #ifndef TEST_INTEROP_CXX_STDLIB_INPUTS_STD_UNIQUE_PTR_H
2
+ #define TEST_INTEROP_CXX_STDLIB_INPUTS_STD_UNIQUE_PTR_H
3
+
4
+ #include < memory>
5
+
6
+ std::unique_ptr<int > makeInt () {
7
+ return std::make_unique<int >(42 );
8
+ }
9
+
10
+ std::unique_ptr<int []> makeArray () {
11
+ int *array = new int [3 ];
12
+ array[0 ] = 1 ;
13
+ array[1 ] = 2 ;
14
+ array[2 ] = 3 ;
15
+ return std::unique_ptr<int []>(array);
16
+ }
17
+
18
+ static bool dtorCalled = false ;
19
+ struct HasDtor {
20
+ ~HasDtor () {
21
+ dtorCalled = true ;
22
+ }
23
+ };
24
+
25
+ std::unique_ptr<HasDtor> makeDtor () {
26
+ return std::make_unique<HasDtor>();
27
+ }
28
+
29
+ #endif // TEST_INTEROP_CXX_STDLIB_INPUTS_STD_UNIQUE_PTR_H
Original file line number Diff line number Diff line change
1
+ // RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop)
2
+ //
3
+ // REQUIRES: executable_test
4
+
5
+ import StdlibUnittest
6
+ import StdUniquePtr
7
+ #if os(Linux)
8
+ import CxxStdlib
9
+ // FIXME: import CxxStdlib.string once libstdc++ is split into submodules.
10
+ #else
11
+ import CxxStdlib. memory
12
+ #endif
13
+
14
+ var StdUniquePtrTestSuite = TestSuite ( " StdUniquePtr " )
15
+
16
+ StdUniquePtrTestSuite . test ( " int " ) {
17
+ let u = makeInt ( )
18
+ expectEqual ( u. pointee, 42 )
19
+ }
20
+
21
+ StdUniquePtrTestSuite . test ( " array " ) {
22
+ var u = makeArray ( )
23
+ expectEqual ( u [ 0 ] , 1 )
24
+ // Over consume:
25
+ // expectEqual(u[1], 2)
26
+ // expectEqual(u[2], 3)
27
+ // Crash:
28
+ // u[0] = 10
29
+ // expectEqual(u[0], 10)
30
+ }
31
+
32
+ StdUniquePtrTestSuite . test ( " custom dtor " ) {
33
+ expectEqual ( dtorCalled, false )
34
+ let c = {
35
+ _ = makeDtor ( )
36
+ }
37
+ c ( )
38
+ expectEqual ( dtorCalled, true )
39
+ }
40
+
41
+ runAllTests ( )
42
+
You can’t perform that action at this time.
0 commit comments