Merge pull request #539 from totalgee/fix_VS2019

Fixes for VS2019 and C++17 compilation
This commit is contained in:
Rob Loach 2020-10-16 09:35:50 -04:00 committed by GitHub
commit c8c9f805f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 157 additions and 121 deletions

View File

@ -1,9 +1,9 @@
version: 6.1.x.{build} version: 6.1.x.{build}
image: image:
- Visual Studio 2017 - Visual Studio 2019
environment: environment:
matrix: matrix:
- VS_VERSION: "Visual Studio 15" - VS_VERSION: "Visual Studio 16"
build_script: build_script:
- cmd: >- - cmd: >-
mkdir build mkdir build

View File

@ -271,7 +271,7 @@ namespace chaiscript {
template<typename ... T> template<typename ... T>
[[nodiscard]] auto make_vector(T && ... t) [[nodiscard]] auto make_vector(T &&... t) -> std::vector<std::common_type_t<std::decay_t<T>...>>
{ {
using container_type = using container_type =
std::vector<std::common_type_t<std::decay_t<T>...>>; std::vector<std::common_type_t<std::decay_t<T>...>>;

View File

@ -185,6 +185,8 @@ namespace chaiscript
return const_var(c_lhs * c_rhs); return const_var(c_lhs * c_rhs);
case Operators::Opers::difference: case Operators::Opers::difference:
return const_var(c_lhs - c_rhs); return const_var(c_lhs - c_rhs);
default:
break;
} }
@ -203,6 +205,8 @@ namespace chaiscript
return const_var(c_lhs | c_rhs); return const_var(c_lhs | c_rhs);
case Operators::Opers::bitwise_xor: case Operators::Opers::bitwise_xor:
return const_var(c_lhs ^ c_rhs); return const_var(c_lhs ^ c_rhs);
default:
break;
} }
} }
@ -224,6 +228,8 @@ namespace chaiscript
case Operators::Opers::assign_difference: case Operators::Opers::assign_difference:
*t_lhs -= c_rhs; *t_lhs -= c_rhs;
return t_bv; return t_bv;
default:
break;
} }
if constexpr (!std::is_floating_point<LHS>::value && !std::is_floating_point<RHS>::value) { if constexpr (!std::is_floating_point<LHS>::value && !std::is_floating_point<RHS>::value) {
@ -247,6 +253,8 @@ namespace chaiscript
case Operators::Opers::assign_bitwise_xor: case Operators::Opers::assign_bitwise_xor:
*t_lhs ^= c_rhs; *t_lhs ^= c_rhs;
return t_bv; return t_bv;
default:
break;
} }
} }
} }
@ -299,6 +307,8 @@ namespace chaiscript
case Operators::Opers::pre_decrement: case Operators::Opers::pre_decrement:
--(*lhs); --(*lhs);
return t_lhs; return t_lhs;
default:
break;
} }
} }
@ -307,12 +317,16 @@ namespace chaiscript
return const_var(-c_lhs); return const_var(-c_lhs);
case Operators::Opers::unary_plus: case Operators::Opers::unary_plus:
return const_var(+c_lhs); return const_var(+c_lhs);
default:
break;
} }
if constexpr (!std::is_floating_point_v<std::decay_t<decltype(c_lhs)>>) { if constexpr (!std::is_floating_point_v<std::decay_t<decltype(c_lhs)>>) {
switch (t_oper) { switch (t_oper) {
case Operators::Opers::bitwise_complement: case Operators::Opers::bitwise_complement:
return const_var(~c_lhs); return const_var(~c_lhs);
default:
break;
} }
} }

View File

@ -1303,8 +1303,8 @@ namespace chaiscript
const auto lhssize = lhsparamtypes.size(); const auto lhssize = lhsparamtypes.size();
const auto rhssize = rhsparamtypes.size(); const auto rhssize = rhsparamtypes.size();
constexpr const auto boxed_type = user_type<Boxed_Value>(); const auto boxed_type = user_type<Boxed_Value>();
constexpr const auto boxed_pod_type = user_type<Boxed_Number>(); const auto boxed_pod_type = user_type<Boxed_Number>();
for (size_t i = 1; i < lhssize && i < rhssize; ++i) for (size_t i = 1; i < lhssize && i < rhssize; ++i)
{ {

View File

@ -39,7 +39,7 @@ namespace chaiscript
{ {
} }
Ret call(const Function_Params &params, const Type_Conversions_State &t_state) Ret call(const chaiscript::Function_Params &params, const Type_Conversions_State &t_state)
{ {
if constexpr (std::is_arithmetic_v<Ret>) { if constexpr (std::is_arithmetic_v<Ret>) {
return Boxed_Number(dispatch::dispatch(m_funcs, params, t_state)).get_as<Ret>(); return Boxed_Number(dispatch::dispatch(m_funcs, params, t_state)).get_as<Ret>();
@ -57,11 +57,11 @@ namespace chaiscript
if (m_conversions) { if (m_conversions) {
Type_Conversions_State state(*m_conversions, m_conversions->conversion_saves()); Type_Conversions_State state(*m_conversions, m_conversions->conversion_saves());
return call(Function_Params{params}, state); return call(chaiscript::Function_Params{params}, state);
} else { } else {
Type_Conversions conv; Type_Conversions conv;
Type_Conversions_State state(conv, conv.conversion_saves()); Type_Conversions_State state(conv, conv.conversion_saves());
return call(Function_Params{params}, state); return call(chaiscript::Function_Params{params}, state);
} }
} }

View File

@ -30,13 +30,13 @@ namespace chaiscript {
} }
explicit Function_Params(const std::vector<Boxed_Value> &vec) explicit Function_Params(const std::vector<Boxed_Value> &vec)
: m_begin(&vec.front()), m_end(&vec.front() + vec.size()) : m_begin(vec.empty() ? nullptr : &vec.front()), m_end(vec.empty() ? nullptr : &vec.front() + vec.size())
{ {
} }
template<size_t Size> template<size_t Size>
constexpr explicit Function_Params(const std::array<Boxed_Value, Size> &a) constexpr explicit Function_Params(const std::array<Boxed_Value, Size> &a)
: m_begin(std::begin(a)), m_end(std::end(a)) : m_begin(&a.front()), m_end(&a.front() + Size)
{ {
} }
@ -74,6 +74,13 @@ namespace chaiscript {
}; };
// Constructor specialization for array of size 0
template<>
constexpr Function_Params::Function_Params(const std::array<Boxed_Value, size_t{0}> & /* a */)
: m_begin(nullptr), m_end(nullptr)
{
}
} }

View File

@ -4,13 +4,15 @@
#include <type_traits> #include <type_traits>
namespace chaiscript::dispatch::detail { namespace chaiscript::dispatch::detail {
template<typename... Param> template<typename... Param>
struct Function_Params struct Function_Params
{ {
}; };
template<typename Ret, typename Params, bool IsNoExcept = false, bool IsMember = false, bool IsMemberObject = false, bool IsObject = false> template<typename Ret, typename Params, bool IsNoExcept = false, bool IsMember = false, bool IsMemberObject = false, bool IsObject = false>
struct Function_Signature { struct Function_Signature
{
using Param_Types = Params; using Param_Types = Params;
using Return_Type = Ret; using Return_Type = Ret;
constexpr static const bool is_object = IsObject; constexpr static const bool is_object = IsObject;
@ -110,15 +112,34 @@ namespace chaiscript::dispatch::detail {
template<typename Ret, typename Class> template<typename Ret, typename Class>
Function_Signature(Ret(Class::*f))->Function_Signature<Ret, Function_Params<Class &>, true, true, true>; Function_Signature(Ret(Class::*f))->Function_Signature<Ret, Function_Params<Class &>, true, true, true>;
// primary template handles types that have no nested ::type member:
template<class, class = std::void_t<>>
struct has_call_operator : std::false_type
{
};
// specialization recognizes types that do have a nested ::type member:
template<class T>
struct has_call_operator<T, std::void_t<decltype(&T::operator())>> : std::true_type
{
};
template<typename Func> template<typename Func>
Function_Signature(Func &&) -> Function_Signature< auto function_signature(const Func &f)
{
if constexpr (has_call_operator<Func>::value) {
return Function_Signature<
typename decltype(Function_Signature{ &std::decay_t<Func>::operator() })::Return_Type, typename decltype(Function_Signature{ &std::decay_t<Func>::operator() })::Return_Type,
typename decltype(Function_Signature{ &std::decay_t<Func>::operator() })::Param_Types, typename decltype(Function_Signature{ &std::decay_t<Func>::operator() })::Param_Types,
decltype(Function_Signature{ &std::decay_t<Func>::operator() })::is_noexcept, decltype(Function_Signature{ &std::decay_t<Func>::operator() })::is_noexcept,
false, false,
false, false,
true true>{};
>; } else {
return Function_Signature{ f };
}
} }
}// namespace chaiscript::dispatch::detail
#endif #endif

View File

@ -77,7 +77,7 @@ namespace chaiscript
std::vector<Boxed_Value> convert(Function_Params t_params, const Type_Conversions_State &t_conversions) const std::vector<Boxed_Value> convert(Function_Params t_params, const Type_Conversions_State &t_conversions) const
{ {
auto vals = t_params.to_vector(); auto vals = t_params.to_vector();
constexpr auto dynamic_object_type_info = user_type<Dynamic_Object>(); const auto dynamic_object_type_info = user_type<Dynamic_Object>();
for (size_t i = 0; i < vals.size(); ++i) for (size_t i = 0; i < vals.size(); ++i)
{ {
const auto &name = m_types[i].first; const auto &name = m_types[i].first;
@ -117,7 +117,7 @@ namespace chaiscript
// second result: needs conversions // second result: needs conversions
std::pair<bool, bool> match(const Function_Params &vals, const Type_Conversions_State &t_conversions) const noexcept std::pair<bool, bool> match(const Function_Params &vals, const Type_Conversions_State &t_conversions) const noexcept
{ {
constexpr auto dynamic_object_type_info = user_type<Dynamic_Object>(); const auto dynamic_object_type_info = user_type<Dynamic_Object>();
bool needs_conversion = false; bool needs_conversion = false;
if (!m_has_types) { return std::make_pair(true, needs_conversion); } if (!m_has_types) { return std::make_pair(true, needs_conversion); }
@ -252,9 +252,9 @@ namespace chaiscript
static bool compare_type_to_param(const Type_Info &ti, const Boxed_Value &bv, const Type_Conversions_State &t_conversions) noexcept static bool compare_type_to_param(const Type_Info &ti, const Boxed_Value &bv, const Type_Conversions_State &t_conversions) noexcept
{ {
constexpr auto boxed_value_ti = user_type<Boxed_Value>(); const auto boxed_value_ti = user_type<Boxed_Value>();
constexpr auto boxed_number_ti = user_type<Boxed_Number>(); const auto boxed_number_ti = user_type<Boxed_Number>();
constexpr auto function_ti = user_type<std::shared_ptr<const Proxy_Function_Base>>(); const auto function_ti = user_type<std::shared_ptr<const Proxy_Function_Base>>();
if (ti.is_undef() if (ti.is_undef()
|| ti.bare_equal(boxed_value_ti) || ti.bare_equal(boxed_value_ti)
@ -757,7 +757,7 @@ namespace chaiscript
{ {
return false; return false;
} }
constexpr auto class_type_info = user_type<Class>(); const auto class_type_info = user_type<Class>();
return vals[0].get_type_info().bare_equal(class_type_info); return vals[0].get_type_info().bare_equal(class_type_info);
} }
@ -844,7 +844,7 @@ namespace chaiscript
namespace detail namespace detail
{ {
template<typename FuncType> template<typename FuncType>
bool types_match_except_for_arithmetic(const FuncType &t_func, const Function_Params &plist, bool types_match_except_for_arithmetic(const FuncType &t_func, const chaiscript::Function_Params &plist,
const Type_Conversions_State &t_conversions) noexcept const Type_Conversions_State &t_conversions) noexcept
{ {
const std::vector<Type_Info> &types = t_func->get_param_types(); const std::vector<Type_Info> &types = t_func->get_param_types();
@ -863,7 +863,7 @@ namespace chaiscript
} }
template<typename InItr, typename Funcs> template<typename InItr, typename Funcs>
Boxed_Value dispatch_with_conversions(InItr begin, const InItr &end, const Function_Params &plist, Boxed_Value dispatch_with_conversions(InItr begin, const InItr &end, const chaiscript::Function_Params &plist,
const Type_Conversions_State &t_conversions, const Funcs &t_funcs) const Type_Conversions_State &t_conversions, const Funcs &t_funcs)
{ {
InItr matching_func(end); InItr matching_func(end);
@ -919,7 +919,7 @@ namespace chaiscript
); );
try { try {
return (*(matching_func->second))(Function_Params{newplist}, t_conversions); return (*(matching_func->second))(chaiscript::Function_Params{newplist}, t_conversions);
} catch (const exception::bad_boxed_cast &) { } catch (const exception::bad_boxed_cast &) {
//parameter failed to cast //parameter failed to cast
} catch (const exception::arity_error &) { } catch (const exception::arity_error &) {

View File

@ -78,7 +78,7 @@ namespace chaiscript
*/ */
template<typename Ret, typename ... Params> template<typename Ret, typename ... Params>
bool compare_types_cast(Ret (*)(Params...), bool compare_types_cast(Ret (*)(Params...),
const Function_Params &params, const Type_Conversions_State &t_conversions) noexcept const chaiscript::Function_Params &params, const Type_Conversions_State &t_conversions) noexcept
{ {
try { try {
std::vector<Boxed_Value>::size_type i = 0; std::vector<Boxed_Value>::size_type i = 0;
@ -93,7 +93,7 @@ namespace chaiscript
template<typename Callable, typename Ret, typename ... Params, size_t ... I> template<typename Callable, typename Ret, typename ... Params, size_t ... I>
Ret call_func(Ret (*)(Params...), Ret call_func(Ret (*)(Params...),
std::index_sequence<I...>, const Callable &f, std::index_sequence<I...>, const Callable &f,
[[maybe_unused]] const Function_Params &params, [[maybe_unused]] const chaiscript::Function_Params &params,
[[maybe_unused]] const Type_Conversions_State &t_conversions) [[maybe_unused]] const Type_Conversions_State &t_conversions)
{ {
return f(boxed_cast<Params>(params[I], &t_conversions)...); return f(boxed_cast<Params>(params[I], &t_conversions)...);
@ -106,7 +106,7 @@ namespace chaiscript
/// the bad_boxed_cast is passed up to the caller. /// the bad_boxed_cast is passed up to the caller.
template<typename Callable, typename Ret, typename ... Params> template<typename Callable, typename Ret, typename ... Params>
Boxed_Value call_func(Ret (*sig)(Params...), const Callable &f, Boxed_Value call_func(Ret (*sig)(Params...), const Callable &f,
const Function_Params &params, const Type_Conversions_State &t_conversions) const chaiscript::Function_Params &params, const Type_Conversions_State &t_conversions)
{ {
if constexpr (std::is_same_v<Ret, void>) { if constexpr (std::is_same_v<Ret, void>) {
call_func(sig, std::index_sequence_for<Params...>{}, f, params, t_conversions); call_func(sig, std::index_sequence_for<Params...>{}, f, params, t_conversions);

View File

@ -34,7 +34,8 @@ namespace chaiscript
// we now that the Param pack will have only one element, so we are safe expanding it here // we now that the Param pack will have only one element, so we are safe expanding it here
return Proxy_Function(chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Attribute_Access<Ret, std::decay_t<Param>...>>(std::forward<Func>(func))); return Proxy_Function(chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Attribute_Access<Ret, std::decay_t<Param>...>>(std::forward<Func>(func)));
} else if constexpr (Is_Member) { } else if constexpr (Is_Member) {
auto call = [func = std::forward<Func>(func)](auto && obj, auto && ... param) noexcept(Is_Noexcept) -> decltype(auto) { // TODO some kind of bug is preventing forwarding of this noexcept for the lambda
auto call = [func = std::forward<Func>(func)](auto && obj, auto && ... param) /* noexcept(Is_Noexcept) */ -> decltype(auto) {
return (( get_first_param(Function_Params<Param...>{}, obj).*func )(std::forward<decltype(param)>(param)...)); return (( get_first_param(Function_Params<Param...>{}, obj).*func )(std::forward<decltype(param)>(param)...));
}; };
return Proxy_Function( return Proxy_Function(
@ -87,7 +88,7 @@ namespace chaiscript
template<typename T> template<typename T>
Proxy_Function fun(T &&t) Proxy_Function fun(T &&t)
{ {
return dispatch::detail::make_callable(std::forward<T>(t), dispatch::detail::Function_Signature{t}); return dispatch::detail::make_callable(std::forward<T>(t), dispatch::detail::function_signature(t));
} }

View File

@ -388,7 +388,7 @@ namespace chaiscript
template<typename T> template<typename T>
bool convertable_type() const noexcept bool convertable_type() const noexcept
{ {
constexpr auto type = user_type<T>().bare_type_info(); const auto type = user_type<T>().bare_type_info();
return thread_cache().count(type) != 0; return thread_cache().count(type) != 0;
} }

View File

@ -713,15 +713,8 @@ TEST_CASE("Object copy counts")
CHECK(Object_Copy_Count_Test::copycount() == 0); CHECK(Object_Copy_Count_Test::copycount() == 0);
CHECK(Object_Copy_Count_Test::constructcount() == 1); CHECK(Object_Copy_Count_Test::constructcount() == 1);
#ifdef CHAISCRIPT_MSVC
CHECK(Object_Copy_Count_Test::destructcount() == 3);
CHECK(Object_Copy_Count_Test::movecount() == 2);
#else
CHECK(Object_Copy_Count_Test::destructcount() == 2); CHECK(Object_Copy_Count_Test::destructcount() == 2);
CHECK(Object_Copy_Count_Test::movecount() == 1); CHECK(Object_Copy_Count_Test::movecount() == 1);
#endif
} }