From 0ae61d6dca2acf788829f56fd9d30777ac981d35 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Mon, 30 Sep 2024 13:08:30 -0700 Subject: [PATCH] fix https://github.com/cppalliance/safe-cpp/issues/65 --- libsafecxx/single-header/std2.h | 2 ++ libsafecxx/test/CMakeLists.txt | 1 + libsafecxx/test/compile-fail/box2.cxx | 13 +++++++++++++ 3 files changed, 16 insertions(+) create mode 100644 libsafecxx/test/compile-fail/box2.cxx diff --git a/libsafecxx/single-header/std2.h b/libsafecxx/single-header/std2.h index 815e324..83c702f 100644 --- a/libsafecxx/single-header/std2.h +++ b/libsafecxx/single-header/std2.h @@ -827,6 +827,8 @@ box { } + box(box const^) = delete; + [[unsafe::drop_only(T)]] ~box() safe { delete p_; diff --git a/libsafecxx/test/CMakeLists.txt b/libsafecxx/test/CMakeLists.txt index ddcd5f5..87c6515 100644 --- a/libsafecxx/test/CMakeLists.txt +++ b/libsafecxx/test/CMakeLists.txt @@ -109,6 +109,7 @@ add_test(NAME "safecxx-verify-headers" COMMAND "${CMAKE_COMMAND}" --build ${CMAK safe_cxx_compile_fail_test(string_view1 "use of sv depends on expired loan") safe_cxx_compile_fail_test(box_incomplete "class incomplete is incomplete") safe_cxx_compile_fail_test(box1 "cannot convert prvalue int to std2::box") +safe_cxx_compile_fail_test(box2 "call to deleted borrow constructor") safe_cxx_compile_fail_test(arc1 "cannot convert prvalue int to std2::arc") safe_cxx_compile_fail_test(rc1 "cannot convert prvalue int to std2::rc") safe_cxx_compile_fail_test(unsafe_cell1 "cannot convert prvalue std2::box to std2::unsafe_cell>") diff --git a/libsafecxx/test/compile-fail/box2.cxx b/libsafecxx/test/compile-fail/box2.cxx new file mode 100644 index 0000000..80adb3b --- /dev/null +++ b/libsafecxx/test/compile-fail/box2.cxx @@ -0,0 +1,13 @@ +// Copyright 2024 Christian Mazakas +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#feature on safety + +#include + +int main() +{ + std2::box p(1234); + auto p2 = cpy p; +}