Skip to content

Commit 5e33984

Browse files
committed
Added compile-fail/array1.cxx
1 parent 7869714 commit 5e33984

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

libsafecxx/test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ endfunction()
106106

107107
add_test(NAME "safecxx-verify-headers" COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target "safe_cxx_verify_interface_header_sets" --config $<CONFIG)
108108

109+
safe_cxx_compile_fail_test(array1 "use of bi depends on expired loan")
109110
safe_cxx_compile_fail_test(string_view1 "use of sv depends on expired loan")
110111
safe_cxx_compile_fail_test(box_incomplete "class incomplete is incomplete")
111112
safe_cxx_compile_fail_test(box1 "cannot convert prvalue int to std2::box<int>")
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// A test for https://github.com/cppalliance/safe-cpp/issues/72
2+
#feature on safety
3+
#include <std2.h>
4+
using namespace std2;
5+
6+
int main() safe {
7+
int i = 0;
8+
int j = 1;
9+
vector<const int^> v { ^const i, ^const j };
10+
11+
const int^ bi = v[0];
12+
13+
// Mutation of i while the loan in v is live should make this
14+
// ill-formed.
15+
i = 1;
16+
17+
// Keep the loan in scope.
18+
int x = *bi;
19+
}

0 commit comments

Comments
 (0)