From 41a45ce8b5085dc34b01741f045a5abafddc8319 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Wed, 14 Jan 2015 21:07:40 -0700 Subject: [PATCH] Enable warnings (and fix up some things) --- CMakeLists.txt | 8 +++++- include/chaiscript/dispatchkit/any.hpp | 4 ++- .../chaiscript/dispatchkit/boxed_number.hpp | 9 +++++- .../chaiscript/dispatchkit/dispatchkit.hpp | 9 ++++++ .../dispatchkit/proxy_functions.hpp | 4 ++- .../dispatchkit/proxy_functions_detail.hpp | 6 ++-- .../chaiscript/language/chaiscript_common.hpp | 2 ++ .../chaiscript/language/chaiscript_eval.hpp | 28 +++++++++---------- 8 files changed, 49 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 034fb5e..03494a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,7 +152,13 @@ if(MSVC) # how to workaround or fix the error. So I'm disabling it globally. add_definitions(/wd4503) else() - add_definitions(-Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -pedantic ${CPP11_FLAG}) + add_definitions(-Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wcast-qual -Woverloaded-virtual -pedantic ${CPP11_FLAG}) + + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + add_definitions(-Weverything -Wno-c++98-compat -Wno-documentation -Wno-switch-enum -Wno-weak-vtables) + else() + add_definitions(-Wnoexcept) + endif() if(APPLE) add_definitions(-Wno-sign-compare) diff --git a/include/chaiscript/dispatchkit/any.hpp b/include/chaiscript/dispatchkit/any.hpp index 7c403b7..8a624b1 100644 --- a/include/chaiscript/dispatchkit/any.hpp +++ b/include/chaiscript/dispatchkit/any.hpp @@ -26,6 +26,8 @@ namespace chaiscript { { } + bad_any_cast(const bad_any_cast &) = default; + virtual ~bad_any_cast() CHAISCRIPT_NOEXCEPT {} /// \brief Description of what error occurred @@ -105,7 +107,7 @@ namespace chaiscript { } } -#if _MSC_VER != 1800 +#if !defined(_MSC_VER) || _MSC_VER != 1800 Any(Any &&) = default; Any &operator=(Any &&t_any) = default; #endif diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index 557a20a..dafe181 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -327,7 +327,7 @@ namespace chaiscript return oss.str(); } - + public: Boxed_Number() : bv(Boxed_Value(0)) @@ -340,6 +340,13 @@ namespace chaiscript validate_boxed_number(bv); } + Boxed_Number(const Boxed_Number &) = default; + +#if !defined(_MSC_VER) || _MSC_VER != 1800 + Boxed_Number(Boxed_Number &&) = default; + Boxed_Number& operator=(Boxed_Number &&) = default; +#endif + template explicit Boxed_Number(T t) : bv(Boxed_Value(t)) { diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index dfa167d..99ade8c 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -62,6 +62,8 @@ namespace chaiscript { } + reserved_word_error(const reserved_word_error &) = default; + virtual ~reserved_word_error() CHAISCRIPT_NOEXCEPT {} std::string word() const @@ -82,6 +84,8 @@ namespace chaiscript { } + illegal_name_error(const illegal_name_error &) = default; + virtual ~illegal_name_error() CHAISCRIPT_NOEXCEPT {} std::string name() const @@ -103,6 +107,8 @@ namespace chaiscript { } + name_conflict_error(const name_conflict_error &) = default; + virtual ~name_conflict_error() CHAISCRIPT_NOEXCEPT {} std::string name() const @@ -125,6 +131,7 @@ namespace chaiscript { } + global_non_const(const global_non_const &) = default; virtual ~global_non_const() CHAISCRIPT_NOEXCEPT {} }; } @@ -389,6 +396,8 @@ namespace chaiscript std::set m_reserved_words; State &operator=(const State &) = default; + State() = default; + State(const State &) = default; }; Dispatch_Engine() diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index fba9b4f..350f65b 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -197,6 +197,8 @@ namespace chaiscript : std::runtime_error("Guard evaluation failed") { } + guard_error(const guard_error &) = default; + virtual ~guard_error() CHAISCRIPT_NOEXCEPT { } }; @@ -560,7 +562,7 @@ namespace chaiscript } } else { throw exception::arity_error(static_cast(params.size()), 1); - } + } } private: diff --git a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp index 744d40b..e5c6f3f 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -42,6 +42,8 @@ namespace chaiscript { } + arity_error(const arity_error &) = default; + virtual ~arity_error() CHAISCRIPT_NOEXCEPT {} int got; @@ -72,7 +74,7 @@ namespace chaiscript template struct Try_Cast { - static void do_try(const std::vector ¶ms, int generation, const Type_Conversions &t_conversions) + static void do_try(const std::vector ¶ms, size_t generation, const Type_Conversions &t_conversions) { boxed_cast(params[generation], &t_conversions); Try_Cast::do_try(params, generation+1, t_conversions); @@ -83,7 +85,7 @@ namespace chaiscript template<> struct Try_Cast<> { - static void do_try(const std::vector &, int, const Type_Conversions &) + static void do_try(const std::vector &, size_t, const Type_Conversions &) { } }; diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index 288b0cc..0cd25c2 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -112,6 +112,8 @@ namespace chaiscript reason(t_why) {} + eval_error(const eval_error &) = default; + std::string pretty_print() const { std::ostringstream ss; diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index be9aabc..aec1e91 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -1333,29 +1333,28 @@ namespace chaiscript AST_NodePtr guardnode; - auto d = t_ss.get_parent_locals(); - auto itr = d.find("_current_class_name"); - int class_offset = 0; - if (itr != d.end()) class_offset = -1; + const auto d = t_ss.get_parent_locals(); + const auto itr = d.find("_current_class_name"); + const auto class_offset = (itr != d.end())?-1:0; const std::string & class_name = (itr != d.end())?std::string(boxed_cast(itr->second)):this->children[0]->text; //The first param of a method is always the implied this ptr. std::vector t_param_names{"this"}; - if ((this->children.size() > static_cast(3 + class_offset)) && (this->children[(2 + class_offset)]->identifier == AST_Node_Type::Arg_List)) { - for (const auto &child : this->children[(2 + class_offset)]->children) { + if ((this->children.size() > static_cast(3 + class_offset)) && (this->children[static_cast(2 + class_offset)]->identifier == AST_Node_Type::Arg_List)) { + for (const auto &child : this->children[static_cast(2 + class_offset)]->children) { t_param_names.push_back(child->text); } if (this->children.size() > static_cast(4 + class_offset)) { - guardnode = this->children[(3 + class_offset)]; + guardnode = this->children[static_cast(3 + class_offset)]; } } else { //no parameters if (this->children.size() > static_cast(3 + class_offset)) { - guardnode = this->children[(2 + class_offset)]; + guardnode = this->children[static_cast(2 + class_offset)]; } } @@ -1372,7 +1371,7 @@ namespace chaiscript try { const std::string & l_annotation = this->annotation?this->annotation->text:""; - const std::string & function_name = this->children[(1 + class_offset)]->text; + const std::string & function_name = this->children[static_cast(1 + class_offset)]->text; if (function_name == class_name) { t_ss.add(std::make_shared(class_name, std::make_shared(std::bind(chaiscript::eval::detail::eval_function, @@ -1420,24 +1419,23 @@ namespace chaiscript { const auto &d = t_ss.get_parent_locals(); const auto itr = d.find("_current_class_name"); - int class_offset = 0; - if (itr != d.end()) class_offset = -1; + const auto class_offset = (itr != d.end())?-1:0; std::string class_name = (itr != d.end())?std::string(boxed_cast(itr->second)):this->children[0]->text; try { t_ss.add( std::make_shared( - class_name, + std::move(class_name), fun(std::function(std::bind(&dispatch::Dynamic_Object::get_attr, std::placeholders::_1, - this->children[(1 + class_offset)]->text + this->children[static_cast(1 + class_offset)]->text )) ) - ), this->children[(1 + class_offset)]->text); + ), this->children[static_cast(1 + class_offset)]->text); } catch (const exception::reserved_word_error &) { - throw exception::eval_error("Reserved word used as attribute '" + this->children[(1 + class_offset)]->text + "'"); + throw exception::eval_error("Reserved word used as attribute '" + this->children[static_cast(1 + class_offset)]->text + "'"); } catch (const exception::name_conflict_error &e) { throw exception::eval_error("Attribute redefined '" + e.name() + "'"); }