From 973e1c3cd6d14b8daf1745c7cbeddf610bd50fd0 Mon Sep 17 00:00:00 2001 From: ShepherdSoasis Date: Wed, 4 Jan 2023 15:35:32 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=20Review=20exhaustive=20check=20an?= =?UTF-8?q?d=20get=20rid=20of=20a=20few=20Wall/pedwarn=20warnings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/sol/stack_check_unqualified.hpp | 3 +- include/sol/stack_core.hpp | 8 +-- include/sol/table_proxy.hpp | 13 +++- tests/CMakeLists.txt | 1 + .../source/exhaustive.cpp | 60 ++++++++++++------- 5 files changed, 54 insertions(+), 31 deletions(-) diff --git a/include/sol/stack_check_unqualified.hpp b/include/sol/stack_check_unqualified.hpp index 37c220bb..0c87d9a0 100644 --- a/include/sol/stack_check_unqualified.hpp +++ b/include/sol/stack_check_unqualified.hpp @@ -608,7 +608,7 @@ namespace sol { namespace stack { } template - static bool check_one(types, lua_State* arg_L, int relindex, type indextype, Handler&& handler, record& tracking) { + static bool check_one(types, lua_State* arg_L, int relindex, type, Handler&& handler, record& tracking) { tracking.use(1); size_t index = lua_absindex(arg_L, relindex); @@ -645,7 +645,6 @@ namespace sol { namespace stack { ++idx; loop_continue:; } - return true; } template diff --git a/include/sol/stack_core.hpp b/include/sol/stack_core.hpp index a037c5b8..c4f5e203 100644 --- a/include/sol/stack_core.hpp +++ b/include/sol/stack_core.hpp @@ -370,10 +370,10 @@ namespace sol { constexpr std::size_t initial_size = aligned_space_for(); - void* pointer_adjusted; - void* dx_adjusted; - void* id_adjusted; - void* data_adjusted; + void* pointer_adjusted = nullptr; + void* dx_adjusted = nullptr; + void* id_adjusted = nullptr; + void* data_adjusted = nullptr; bool result = attempt_alloc_unique(L, std::alignment_of_v, sizeof(T*), diff --git a/include/sol/table_proxy.hpp b/include/sol/table_proxy.hpp index 1cb1e9de..13c9006f 100644 --- a/include/sol/table_proxy.hpp +++ b/include/sol/table_proxy.hpp @@ -77,6 +77,15 @@ namespace sol { table_proxy(Table table, T&& k) : tbl(table), key(std::forward(k)) { } + table_proxy(const table_proxy&) = default; + table_proxy(table_proxy&&) = default; + table_proxy& operator=(const table_proxy& right) { + return set(right); + } + table_proxy& operator=(table_proxy&& right) { + return set(std::move(right)); + } + template table_proxy& set(T&& item) & { tuple_set(std::make_index_sequence>>(), std::forward(item)); @@ -101,7 +110,7 @@ namespace sol { return std::move(*this); } - template + template , table_proxy>>* = nullptr> table_proxy& operator=(T&& other) & { using Tu = meta::unwrap_unqualified_t; if constexpr (!is_lua_reference_or_proxy_v && meta::is_invocable_v) { @@ -112,7 +121,7 @@ namespace sol { } } - template + template , table_proxy>>* = nullptr> table_proxy&& operator=(T&& other) && { using Tu = meta::unwrap_unqualified_t; if constexpr (!is_lua_reference_or_proxy_v && meta::is_invocable_v && !detail::is_msvc_callable_rigged_v) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f727763b..e08a7b49 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -83,6 +83,7 @@ function(sol2_create_basic_test test_target_name target_sol) endfunction() add_subdirectory(inclusion) +add_subdirectory(container_exhaustive) add_subdirectory(enum) add_subdirectory(environment) add_subdirectory(exceptions) diff --git a/tests/container_exhaustive/source/exhaustive.cpp b/tests/container_exhaustive/source/exhaustive.cpp index b5fcf9c2..36b489a4 100644 --- a/tests/container_exhaustive/source/exhaustive.cpp +++ b/tests/container_exhaustive/source/exhaustive.cpp @@ -39,10 +39,12 @@ inline namespace sol2_tests_exhaustive { inline constexpr int FAILURE_CONSTANT = 1000; + inline constexpr int LINK_CONSTANT = 0xA837; + inline int ex_f0(sol::exhaustive> ex_vec) { const auto& vec = ex_vec.value(); for (const auto& elem : vec) { - REQUIRE(elem.value == 0); + REQUIRE(elem.value == LINK_CONSTANT); } return 0; } @@ -56,10 +58,11 @@ inline namespace sol2_tests_exhaustive { return 1; } - inline int ex_f2(sol::exhaustive> ex_vec) { + inline int ex_f2(sol::exhaustive> ex_vec, sol::this_state this_lua) { const auto& vec = ex_vec.value(); + void* address = static_cast(this_lua.lua_state()); for (const auto& elem : vec) { - REQUIRE(elem.value == nullptr); + REQUIRE(elem.value == address); } return 2; } @@ -74,9 +77,11 @@ TEST_CASE("large_integer/bool", "pass bool integral value to and from lua") { sol::state lua; lua.open_libraries(sol::lib::base); + void* address = lua.lua_state(); + lua["FAILURE_CONSTANT"] = FAILURE_CONSTANT; - lua["link_obj"] = Link { 0 }; - lua["nonlink_obj"] = NonLink { nullptr }; + lua["link_obj"] = Link { LINK_CONSTANT }; + lua["nonlink_obj"] = NonLink { address }; sol::optional setup_result = lua.safe_script(R"( expect0_0 = { link_obj, link_obj, link_obj, link_obj } @@ -89,22 +94,31 @@ TEST_CASE("large_integer/bool", "pass bool integral value to and from lua") { REQUIRE_FALSE(setup_result.has_value()); lua.set_function("get_table_exhaustive", sol::overload(ex_f0, ex_f1, ex_f2, ex_ffail)); - - sol::optional result = lua.safe_script(R"( - result0_0 = get_table_exhaustive(expect0_0) - assert(result0_0 == 0) - result0_1 = get_table_exhaustive(expect0_1) - assert(result0_1 == FAILURE_CONSTANT) - - result1_0 = get_table_exhaustive(expect1_0) - assert(result1_0 == 1) - result1_1 = get_table_exhaustive(expect1_1) - assert(result1_1 == FAILURE_CONSTANT) - - result2_0 = get_table_exhaustive(expect2_0) - assert(result2_0 == 2) - result2_1 = get_table_exhaustive(expect2_1) - assert(result2_1 == FAILURE_CONSTANT) - )"); - REQUIRE_FALSE(result.has_value()); + { + sol::optional result = lua.safe_script(R"( + result0_0 = get_table_exhaustive(expect0_0) + assert(result0_0 == 0) + result0_1 = get_table_exhaustive(expect0_1) + assert(result0_1 == FAILURE_CONSTANT) + )"); + REQUIRE_FALSE(result.has_value()); + } + { + sol::optional result = lua.safe_script(R"( + result1_0 = get_table_exhaustive(expect1_0) + assert(result1_0 == 1) + result1_1 = get_table_exhaustive(expect1_1) + assert(result1_1 == FAILURE_CONSTANT) + )"); + REQUIRE_FALSE(result.has_value()); + } + { + sol::optional result = lua.safe_script(R"( + result2_0 = get_table_exhaustive(expect2_0) + assert(result2_0 == 2) + result2_1 = get_table_exhaustive(expect2_1) + assert(result2_1 == FAILURE_CONSTANT) + )"); + REQUIRE_FALSE(result.has_value()); + } }