Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 973e1c3

Browse files
ShepherdSoasisThePhD
authored andcommitted
🛠 Review exhaustive check and get rid of a few Wall/pedwarn warnings
1 parent f81643a commit 973e1c3

File tree

5 files changed

+54
-31
lines changed

5 files changed

+54
-31
lines changed

‎include/sol/stack_check_unqualified.hpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ namespace sol { namespace stack {
608608
}
609609

610610
template <typename V, typename Handler>
611-
static bool check_one(types<V>, lua_State* arg_L, int relindex, type indextype, Handler&& handler, record& tracking) {
611+
static bool check_one(types<V>, lua_State* arg_L, int relindex, type, Handler&& handler, record& tracking) {
612612
tracking.use(1);
613613

614614
size_t index = lua_absindex(arg_L, relindex);
@@ -645,7 +645,6 @@ namespace sol { namespace stack {
645645
++idx;
646646
loop_continue:;
647647
}
648-
return true;
649648
}
650649

651650
template <typename Handler>

‎include/sol/stack_core.hpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,10 @@ namespace sol {
370370

371371
constexpr std::size_t initial_size = aligned_space_for<T*, unique_destructor, unique_tag, Real>();
372372

373-
void* pointer_adjusted;
374-
void* dx_adjusted;
375-
void* id_adjusted;
376-
void* data_adjusted;
373+
void* pointer_adjusted = nullptr;
374+
void* dx_adjusted = nullptr;
375+
void* id_adjusted = nullptr;
376+
void* data_adjusted = nullptr;
377377
bool result = attempt_alloc_unique(L,
378378
std::alignment_of_v<T*>,
379379
sizeof(T*),

‎include/sol/table_proxy.hpp‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ namespace sol {
7777
table_proxy(Table table, T&& k) : tbl(table), key(std::forward<T>(k)) {
7878
}
7979

80+
table_proxy(const table_proxy&) = default;
81+
table_proxy(table_proxy&&) = default;
82+
table_proxy& operator=(const table_proxy& right) {
83+
return set(right);
84+
}
85+
table_proxy& operator=(table_proxy&& right) {
86+
return set(std::move(right));
87+
}
88+
8089
template <typename T>
8190
table_proxy& set(T&& item) & {
8291
tuple_set(std::make_index_sequence<std::tuple_size_v<meta::unqualified_t<key_type>>>(), std::forward<T>(item));
@@ -101,7 +110,7 @@ namespace sol {
101110
return std::move(*this);
102111
}
103112

104-
template <typename T>
113+
template <typename T, std::enable_if_t<!std::is_same_v<meta::unqualified_t<T>, table_proxy>>* = nullptr>
105114
table_proxy& operator=(T&& other) & {
106115
using Tu = meta::unwrap_unqualified_t<T>;
107116
if constexpr (!is_lua_reference_or_proxy_v<Tu> && meta::is_invocable_v<Tu>) {
@@ -112,7 +121,7 @@ namespace sol {
112121
}
113122
}
114123

115-
template <typename T>
124+
template <typename T, std::enable_if_t<!std::is_same_v<meta::unqualified_t<T>, table_proxy>>* = nullptr>
116125
table_proxy&& operator=(T&& other) && {
117126
using Tu = meta::unwrap_unqualified_t<T>;
118127
if constexpr (!is_lua_reference_or_proxy_v<Tu> && meta::is_invocable_v<Tu> && !detail::is_msvc_callable_rigged_v<T>) {

‎tests/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ function(sol2_create_basic_test test_target_name target_sol)
8383
endfunction()
8484

8585
add_subdirectory(inclusion)
86+
add_subdirectory(container_exhaustive)
8687
add_subdirectory(enum)
8788
add_subdirectory(environment)
8889
add_subdirectory(exceptions)

‎tests/container_exhaustive/source/exhaustive.cpp‎

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ inline namespace sol2_tests_exhaustive {
3939

4040
inline constexpr int FAILURE_CONSTANT = 1000;
4141

42+
inline constexpr int LINK_CONSTANT = 0xA837;
43+
4244
inline int ex_f0(sol::exhaustive<std::vector<Link>> ex_vec) {
4345
const auto& vec = ex_vec.value();
4446
for (const auto& elem : vec) {
45-
REQUIRE(elem.value == 0);
47+
REQUIRE(elem.value == LINK_CONSTANT);
4648
}
4749
return 0;
4850
}
@@ -56,10 +58,11 @@ inline namespace sol2_tests_exhaustive {
5658
return 1;
5759
}
5860

59-
inline int ex_f2(sol::exhaustive<std::vector<NonLink>> ex_vec) {
61+
inline int ex_f2(sol::exhaustive<std::vector<NonLink>> ex_vec, sol::this_state this_lua) {
6062
const auto& vec = ex_vec.value();
63+
void* address = static_cast<void*>(this_lua.lua_state());
6164
for (const auto& elem : vec) {
62-
REQUIRE(elem.value == nullptr);
65+
REQUIRE(elem.value == address);
6366
}
6467
return 2;
6568
}
@@ -74,9 +77,11 @@ TEST_CASE("large_integer/bool", "pass bool integral value to and from lua") {
7477
sol::state lua;
7578
lua.open_libraries(sol::lib::base);
7679

80+
void* address = lua.lua_state();
81+
7782
lua["FAILURE_CONSTANT"] = FAILURE_CONSTANT;
78-
lua["link_obj"] = Link { 0 };
79-
lua["nonlink_obj"] = NonLink { nullptr };
83+
lua["link_obj"] = Link { LINK_CONSTANT };
84+
lua["nonlink_obj"] = NonLink { address };
8085

8186
sol::optional<sol::error> setup_result = lua.safe_script(R"(
8287
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") {
8994
REQUIRE_FALSE(setup_result.has_value());
9095

9196
lua.set_function("get_table_exhaustive", sol::overload(ex_f0, ex_f1, ex_f2, ex_ffail));
92-
93-
sol::optional<sol::error> result = lua.safe_script(R"(
94-
result0_0 = get_table_exhaustive(expect0_0)
95-
assert(result0_0 == 0)
96-
result0_1 = get_table_exhaustive(expect0_1)
97-
assert(result0_1 == FAILURE_CONSTANT)
98-
99-
result1_0 = get_table_exhaustive(expect1_0)
100-
assert(result1_0 == 1)
101-
result1_1 = get_table_exhaustive(expect1_1)
102-
assert(result1_1 == FAILURE_CONSTANT)
103-
104-
result2_0 = get_table_exhaustive(expect2_0)
105-
assert(result2_0 == 2)
106-
result2_1 = get_table_exhaustive(expect2_1)
107-
assert(result2_1 == FAILURE_CONSTANT)
108-
)");
109-
REQUIRE_FALSE(result.has_value());
97+
{
98+
sol::optional<sol::error> result = lua.safe_script(R"(
99+
result0_0 = get_table_exhaustive(expect0_0)
100+
assert(result0_0 == 0)
101+
result0_1 = get_table_exhaustive(expect0_1)
102+
assert(result0_1 == FAILURE_CONSTANT)
103+
)");
104+
REQUIRE_FALSE(result.has_value());
105+
}
106+
{
107+
sol::optional<sol::error> result = lua.safe_script(R"(
108+
result1_0 = get_table_exhaustive(expect1_0)
109+
assert(result1_0 == 1)
110+
result1_1 = get_table_exhaustive(expect1_1)
111+
assert(result1_1 == FAILURE_CONSTANT)
112+
)");
113+
REQUIRE_FALSE(result.has_value());
114+
}
115+
{
116+
sol::optional<sol::error> result = lua.safe_script(R"(
117+
result2_0 = get_table_exhaustive(expect2_0)
118+
assert(result2_0 == 2)
119+
result2_1 = get_table_exhaustive(expect2_1)
120+
assert(result2_1 == FAILURE_CONSTANT)
121+
)");
122+
REQUIRE_FALSE(result.has_value());
123+
}
110124
}

0 commit comments

Comments
 (0)