Skip to content

Commit df5d08e

Browse files
Synchronize changes from 1.6 master branch [ci skip]
bd96522 Fix argument parser not handling noexcept functions (PR #4404)
2 parents 5c95fc7 + bd96522 commit df5d08e

File tree

3 files changed

+47
-12
lines changed

3 files changed

+47
-12
lines changed

Client/mods/deathmatch/logic/luadefs/CLuaDefs.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class CLuaDefs
7777
template <auto ReturnOnError, auto T>
7878
static inline int ArgumentParserWarn(lua_State* L)
7979
{
80-
return CLuaFunctionParser<false, ReturnOnError, T>()(L, m_pScriptDebugging);
80+
return CLuaFunctionParser<false, ReturnOnError, remove_noexcept_fn_v<T>>()(L, m_pScriptDebugging);
8181
}
8282

8383
// Special case for overloads
@@ -87,8 +87,8 @@ class CLuaDefs
8787
{
8888
// Pad functions to have the same number of parameters by
8989
// filling both up to the larger number of parameters with dummy_type arguments
90-
using PaddedFunctionA = pad_func_with_func<FunctionA, FunctionB>;
91-
using PaddedFunctionB = pad_func_with_func<FunctionB, FunctionA>;
90+
using PaddedFunctionA = pad_func_with_func<remove_noexcept_fn_v<FunctionA>, remove_noexcept_fn_v<FunctionB>>;
91+
using PaddedFunctionB = pad_func_with_func<remove_noexcept_fn_v<FunctionB>, remove_noexcept_fn_v<FunctionA>>;
9292
// Combine functions
9393
using Overload = CLuaOverloadParser<PaddedFunctionA::Call, PaddedFunctionB::Call>;
9494

@@ -99,7 +99,7 @@ class CLuaDefs
9999
template <auto T>
100100
static inline int ArgumentParser(lua_State* L)
101101
{
102-
return CLuaFunctionParser<true, nullptr, T>()(L, m_pScriptDebugging);
102+
return CLuaFunctionParser<true, nullptr, remove_noexcept_fn_v<T>>()(L, m_pScriptDebugging);
103103
}
104104

105105
// Special case for overloads
@@ -109,8 +109,8 @@ class CLuaDefs
109109
{
110110
// Pad functions to have the same number of parameters by
111111
// filling both up to the larger number of parameters with dummy_type arguments
112-
using PaddedFunctionA = pad_func_with_func<FunctionA, FunctionB>;
113-
using PaddedFunctionB = pad_func_with_func<FunctionB, FunctionA>;
112+
using PaddedFunctionA = pad_func_with_func<remove_noexcept_fn_v<FunctionA>, remove_noexcept_fn_v<FunctionB>>;
113+
using PaddedFunctionB = pad_func_with_func<remove_noexcept_fn_v<FunctionB>, remove_noexcept_fn_v<FunctionA>>;
114114
// Combine functions
115115
using Overload = CLuaOverloadParser<PaddedFunctionA::Call, PaddedFunctionB::Call>;
116116

Server/mods/deathmatch/logic/luadefs/CLuaDefs.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class CLuaDefs
9696
template <auto ReturnOnError, auto T>
9797
static inline int ArgumentParserWarn(lua_State* L)
9898
{
99-
return CLuaFunctionParser<false, ReturnOnError, T>()(L, m_pScriptDebugging);
99+
return CLuaFunctionParser<false, ReturnOnError, remove_noexcept_fn_v<T>>()(L, m_pScriptDebugging);
100100
}
101101

102102
// Special case for overloads
@@ -106,8 +106,8 @@ class CLuaDefs
106106
{
107107
// Pad functions to have the same number of parameters by
108108
// filling both up to the larger number of parameters with dummy_type arguments
109-
using PaddedFunctionA = pad_func_with_func<FunctionA, FunctionB>;
110-
using PaddedFunctionB = pad_func_with_func<FunctionB, FunctionA>;
109+
using PaddedFunctionA = pad_func_with_func<remove_noexcept_fn_v<FunctionA>, remove_noexcept_fn_v<FunctionB>>;
110+
using PaddedFunctionB = pad_func_with_func<remove_noexcept_fn_v<FunctionB>, remove_noexcept_fn_v<FunctionA>>;
111111
// Combine functions
112112
using Overload = CLuaOverloadParser<PaddedFunctionA::Call, PaddedFunctionB::Call>;
113113

@@ -118,7 +118,7 @@ class CLuaDefs
118118
template <auto T>
119119
static inline int ArgumentParser(lua_State* L)
120120
{
121-
return CLuaFunctionParser<true, nullptr, T>()(L, m_pScriptDebugging);
121+
return CLuaFunctionParser<true, nullptr, remove_noexcept_fn_v<T>>()(L, m_pScriptDebugging);
122122
}
123123

124124
// Special case for overloads
@@ -128,8 +128,8 @@ class CLuaDefs
128128
{
129129
// Pad functions to have the same number of parameters by
130130
// filling both up to the larger number of parameters with dummy_type arguments
131-
using PaddedFunctionA = pad_func_with_func<FunctionA, FunctionB>;
132-
using PaddedFunctionB = pad_func_with_func<FunctionB, FunctionA>;
131+
using PaddedFunctionA = pad_func_with_func<remove_noexcept_fn_v<FunctionA>, remove_noexcept_fn_v<FunctionB>>;
132+
using PaddedFunctionB = pad_func_with_func<remove_noexcept_fn_v<FunctionB>, remove_noexcept_fn_v<FunctionA>>;
133133
// Combine functions
134134
using Overload = CLuaOverloadParser<PaddedFunctionA::Call, PaddedFunctionB::Call>;
135135

Shared/sdk/SharedUtil.Template.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,38 @@ struct pad_func_with_func<Func, FuncB>
250250
std::max(sizeof...(Args), sizeof...(ArgsB)) - sizeof...(Args) == 0>::type>
251251
{
252252
};
253+
254+
// Removes noexcept(true) from a function type
255+
template <typename T>
256+
struct remove_noexcept
257+
{
258+
using type = T;
259+
};
260+
261+
template <typename R, typename... Args>
262+
struct remove_noexcept<R(Args...) noexcept>
263+
{
264+
using type = R(Args...);
265+
};
266+
267+
template <typename T>
268+
using remove_noexcept_t = typename remove_noexcept<T>::type;
269+
270+
// Removes noexcept(true) from a function
271+
template <typename T>
272+
struct remove_noexcept_fn;
273+
274+
template <typename R, typename... Args>
275+
struct remove_noexcept_fn<R (*)(Args...) noexcept>
276+
{
277+
using type = R (*)(Args...);
278+
};
279+
280+
template <typename R, typename... Args>
281+
struct remove_noexcept_fn<R (*)(Args...)>
282+
{
283+
using type = R (*)(Args...);
284+
};
285+
286+
template <auto Func>
287+
constexpr auto remove_noexcept_fn_v = static_cast<typename remove_noexcept_fn<decltype(Func)>::type>(Func);

0 commit comments

Comments
 (0)