diff --git a/CMakeLists.txt b/CMakeLists.txt index effc7aed..e98ed1d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,6 +170,10 @@ endif() if(MSVC) add_definitions(/W4 /w14545 /w34242 /w34254 /w34287 /w44263 /w44265 /w44296 /w44311 /w44826 /we4289 /w14546 /w14547 /w14549 /w14555 /w14619 /w14905 /w14906 /w14928) + if (BUILD_IN_CPP17_MODE) + add_definitions(/std:c++17) + endif() + if (MSVC_VERSION STREQUAL "1800") # VS2013 doesn't have magic statics add_definitions(/w44640) diff --git a/include/chaiscript/chaiscript_defines.hpp b/include/chaiscript/chaiscript_defines.hpp index 4c303307..93d9187e 100644 --- a/include/chaiscript/chaiscript_defines.hpp +++ b/include/chaiscript/chaiscript_defines.hpp @@ -170,7 +170,7 @@ namespace chaiscript { auto parse_num(const char *t_str) -> typename std::enable_if::value, T>::type { T t = 0; - T base; + T base{}; T decimal_place = 0; int exponent = 0; diff --git a/include/chaiscript/dispatchkit/register_function.hpp b/include/chaiscript/dispatchkit/register_function.hpp index e660790d..2206b024 100644 --- a/include/chaiscript/dispatchkit/register_function.hpp +++ b/include/chaiscript/dispatchkit/register_function.hpp @@ -86,7 +86,7 @@ namespace chaiscript // only compile this bit if noexcept is part of the type system // -#if __cpp_noexcept_function_type >= 201510 +#if __cpp_noexcept_function_type >= 201510 || (_MSVC_LANG > 201403L && _MSC_VER >= 1912) template Proxy_Function fun(Ret (*func)(Param...) noexcept) { diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index ed3b1141..8f0c0aa1 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -54,8 +54,8 @@ #include "../dispatchkit/exception_specification.hpp" namespace chaiscript -{ - /// Namespace alias to provide cleaner and more explicit syntax to users. +{ + /// Namespace alias to provide cleaner and more explicit syntax to users. using Namespace = dispatch::Dynamic_Object; namespace detail @@ -200,7 +200,7 @@ namespace chaiscript m_engine.add(fun([this](const Boxed_Value &t_bv, const std::string &t_name){ add_global(t_bv, t_name); }), "add_global"); m_engine.add(fun([this](const Boxed_Value &t_bv, const std::string &t_name){ set_global(t_bv, t_name); }), "set_global"); - m_engine.add(fun([this](const std::string& t_namespace_name) { register_namespace([](Namespace& space) {}, t_namespace_name); import(t_namespace_name); }), "namespace"); + m_engine.add(fun([this](const std::string& t_namespace_name) { register_namespace([](Namespace& /*space*/) {}, t_namespace_name); import(t_namespace_name); }), "namespace"); m_engine.add(fun([this](const std::string& t_namespace_name) { import(t_namespace_name); }), "import"); } @@ -711,39 +711,39 @@ explicit ChaiScript_Basic(std::unique_ptr &&pars return m_engine.boxed_cast(eval_file(t_filename, t_handler)); } - /// \brief Imports a namespace object into the global scope of this ChaiScript instance. - /// \param[in] t_namespace_name Name of the namespace to import. - /// \throw std::runtime_error In the case that the namespace name was never registered. - void import(const std::string& t_namespace_name) - { - chaiscript::detail::threading::unique_lock l(m_use_mutex); - - if (m_engine.get_scripting_objects().count(t_namespace_name)) { - throw std::runtime_error("Namespace: " + t_namespace_name + " was already defined"); - } - else if (m_namespace_generators.count(t_namespace_name)) { - m_engine.add_global(var(std::ref(m_namespace_generators[t_namespace_name]())), t_namespace_name); - } - else { - throw std::runtime_error("No registered namespace: " + t_namespace_name); - } - } - - /// \brief Registers a namespace generator, which delays generation of the namespace until it is imported, saving memory if it is never used. - /// \param[in] t_namespace_generator Namespace generator function. - /// \param[in] t_namespace_name Name of the Namespace function being registered. - /// \throw std::runtime_error In the case that the namespace name was already registered. - void register_namespace(const std::function& t_namespace_generator, const std::string& t_namespace_name) - { - chaiscript::detail::threading::unique_lock l(m_use_mutex); - - if (!m_namespace_generators.count(t_namespace_name)) { - // contain the namespace object memory within the m_namespace_generators map - m_namespace_generators.emplace(std::make_pair(t_namespace_name, [=, space = Namespace()]() mutable -> Namespace& { t_namespace_generator(space); return space; })); - } - else { - throw std::runtime_error("Namespace: " + t_namespace_name + " was already registered."); - } + /// \brief Imports a namespace object into the global scope of this ChaiScript instance. + /// \param[in] t_namespace_name Name of the namespace to import. + /// \throw std::runtime_error In the case that the namespace name was never registered. + void import(const std::string& t_namespace_name) + { + chaiscript::detail::threading::unique_lock l(m_use_mutex); + + if (m_engine.get_scripting_objects().count(t_namespace_name)) { + throw std::runtime_error("Namespace: " + t_namespace_name + " was already defined"); + } + else if (m_namespace_generators.count(t_namespace_name)) { + m_engine.add_global(var(std::ref(m_namespace_generators[t_namespace_name]())), t_namespace_name); + } + else { + throw std::runtime_error("No registered namespace: " + t_namespace_name); + } + } + + /// \brief Registers a namespace generator, which delays generation of the namespace until it is imported, saving memory if it is never used. + /// \param[in] t_namespace_generator Namespace generator function. + /// \param[in] t_namespace_name Name of the Namespace function being registered. + /// \throw std::runtime_error In the case that the namespace name was already registered. + void register_namespace(const std::function& t_namespace_generator, const std::string& t_namespace_name) + { + chaiscript::detail::threading::unique_lock l(m_use_mutex); + + if (!m_namespace_generators.count(t_namespace_name)) { + // contain the namespace object memory within the m_namespace_generators map + m_namespace_generators.emplace(std::make_pair(t_namespace_name, [=, space = Namespace()]() mutable -> Namespace& { t_namespace_generator(space); return space; })); + } + else { + throw std::runtime_error("Namespace: " + t_namespace_name + " was already registered."); + } } };