From f95ca75acaaeceaa505ddb48bba0f1ccec9feaac Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 15 Jan 2015 14:24:39 -0700 Subject: [PATCH] Clean up more warnings with stricter warning levels --- CMakeLists.txt | 2 +- .../chaiscript/dispatchkit/bad_boxed_cast.hpp | 3 +- include/chaiscript/dispatchkit/bootstrap.hpp | 2 +- .../chaiscript/dispatchkit/boxed_number.hpp | 20 +++++++++---- .../chaiscript/dispatchkit/boxed_value.hpp | 2 +- .../dispatchkit/proxy_functions.hpp | 16 +++++------ .../dispatchkit/type_conversions.hpp | 8 ++++-- .../chaiscript/language/chaiscript_common.hpp | 3 +- .../chaiscript/language/chaiscript_engine.hpp | 5 ++-- .../chaiscript/language/chaiscript_parser.hpp | 5 ++-- src/main.cpp | 28 ++++++++++--------- src/test_module.cpp | 5 ++++ unittests/functor_cast_test.cpp | 14 +++++----- unittests/object_lifetime_test2.cpp | 6 ++-- 14 files changed, 71 insertions(+), 48 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03494a1..90d6f84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,7 +155,7 @@ else() 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) + add_definitions(-Weverything -Wno-c++98-compat -Wno-documentation -Wno-switch-enum -Wno-weak-vtables -Wno-sign-conversion -Wno-missing-prototypes -Wno-padded) else() add_definitions(-Wnoexcept) endif() diff --git a/include/chaiscript/dispatchkit/bad_boxed_cast.hpp b/include/chaiscript/dispatchkit/bad_boxed_cast.hpp index 648eb41..ca2071b 100644 --- a/include/chaiscript/dispatchkit/bad_boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/bad_boxed_cast.hpp @@ -45,7 +45,8 @@ namespace chaiscript { } - virtual ~bad_boxed_cast() CHAISCRIPT_NOEXCEPT {} + bad_boxed_cast(const bad_boxed_cast &) = default; + virtual ~bad_boxed_cast() CHAISCRIPT_NOEXCEPT = default; /// \brief Description of what error occurred virtual const char * what() const CHAISCRIPT_NOEXCEPT CHAISCRIPT_OVERRIDE diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 3e88daf..c43820f 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -298,7 +298,7 @@ namespace chaiscript } } - static void throw_exception(const Boxed_Value &bv) { + static void throw_exception [[ noreturn ]] (const Boxed_Value &bv) { throw bv; } diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index dafe181..f4264cd 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -33,6 +33,15 @@ namespace chaiscript #pragma warning(disable : 4244 4018 4389 4146 4365) #endif + +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wfloat-equal" +#pragma GCC diagnostic ignored "-Wconversion" +#pragma GCC diagnostic ignored "-Wsign-conversion" +#endif + /// \brief Represents any numeric type, generically. Used internally for generic operations between POD values class Boxed_Number { @@ -40,9 +49,6 @@ namespace chaiscript struct boolean { -#ifdef __GNUC__ -#pragma GCC diagnostic ignored "-Wsign-compare" -#endif template static Boxed_Value go(Operators::Opers t_oper, const T &t, const U &u, const Boxed_Value &) { @@ -850,14 +856,18 @@ namespace chaiscript struct Cast_Helper : Cast_Helper { }; - + /// Cast_Helper for converting from Boxed_Value to Boxed_Number template<> struct Cast_Helper : Cast_Helper { - }; + }; } +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + #ifdef CHAISCRIPT_MSVC #pragma warning(pop) #endif diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index c73358c..65ed7a6 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -72,8 +72,8 @@ namespace chaiscript chaiscript::detail::Any m_obj; void *m_data_ptr; const void *m_const_data_ptr; - bool m_is_ref; std::unique_ptr> m_attrs; + bool m_is_ref; }; struct Object_Data diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index 350f65b..61d9d47 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -129,7 +129,7 @@ namespace chaiscript virtual Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions &t_conversions) const = 0; Proxy_Function_Base(std::vector t_types, int t_arity) - : m_types(std::move(t_types)), m_has_arithmetic_param(false), m_arity(t_arity) + : m_types(std::move(t_types)), m_arity(t_arity), m_has_arithmetic_param(false) { for (size_t i = 1; i < m_types.size(); ++i) { @@ -175,8 +175,8 @@ namespace chaiscript } std::vector m_types; - bool m_has_arithmetic_param; int m_arity; + bool m_has_arithmetic_param; }; } @@ -220,11 +220,11 @@ namespace chaiscript std::string t_description = "", Proxy_Function t_guard = Proxy_Function()) : Proxy_Function_Base(build_param_type_list(t_arity), t_arity), - m_f(std::move(t_f)), m_arity(t_arity), m_description(std::move(t_description)), m_guard(std::move(t_guard)), m_parsenode(std::move(t_parsenode)) + m_guard(std::move(t_guard)), m_parsenode(std::move(t_parsenode)), m_description(std::move(t_description)), m_f(std::move(t_f)) { } - virtual ~Dynamic_Proxy_Function() {} + virtual ~Dynamic_Proxy_Function() = default; virtual bool operator==(const Proxy_Function_Base &rhs) const CHAISCRIPT_OVERRIDE { @@ -311,11 +311,10 @@ namespace chaiscript return types; } - std::function &)> m_f; - int m_arity; - std::string m_description; Proxy_Function m_guard; AST_NodePtr m_parsenode; + std::string m_description; + std::function &)> m_f; }; /** @@ -591,7 +590,8 @@ namespace chaiscript { } - virtual ~dispatch_error() CHAISCRIPT_NOEXCEPT {} + dispatch_error(const dispatch_error &) = default; + virtual ~dispatch_error() CHAISCRIPT_NOEXCEPT = default; std::vector parameters; std::vector functions; diff --git a/include/chaiscript/dispatchkit/type_conversions.hpp b/include/chaiscript/dispatchkit/type_conversions.hpp index 59ad5e3..6fd9a17 100644 --- a/include/chaiscript/dispatchkit/type_conversions.hpp +++ b/include/chaiscript/dispatchkit/type_conversions.hpp @@ -44,7 +44,9 @@ namespace chaiscript { } - virtual ~bad_boxed_dynamic_cast() CHAISCRIPT_NOEXCEPT {} + bad_boxed_dynamic_cast(const bad_boxed_dynamic_cast &) = default; + + virtual ~bad_boxed_dynamic_cast() CHAISCRIPT_NOEXCEPT = default; }; class bad_boxed_type_cast : public bad_boxed_cast @@ -66,7 +68,9 @@ namespace chaiscript { } - virtual ~bad_boxed_type_cast() CHAISCRIPT_NOEXCEPT {} + bad_boxed_type_cast(const bad_boxed_type_cast &) = default; + + virtual ~bad_boxed_type_cast() CHAISCRIPT_NOEXCEPT = default; }; } diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index 0cd25c2..fb1d213 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -397,7 +397,8 @@ namespace chaiscript : std::runtime_error("File Not Found: " + t_filename) { } - virtual ~file_not_found_error() CHAISCRIPT_NOEXCEPT {} + file_not_found_error(const file_not_found_error &) = default; + virtual ~file_not_found_error() CHAISCRIPT_NOEXCEPT = default; }; } diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 7fa4dd6..6478c59 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -61,9 +61,8 @@ namespace chaiscript { } - virtual ~load_module_error() CHAISCRIPT_NOEXCEPT - { - } + load_module_error(const load_module_error &) = default; + virtual ~load_module_error() CHAISCRIPT_NOEXCEPT = default; }; } diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index f090ba6..8dda17c 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -223,8 +223,8 @@ namespace chaiscript t_t->end.column = pos_col_stop; if (is_deep) { - t_t->children.assign(m_match_stack.begin() + t_match_start, m_match_stack.end()); - m_match_stack.erase(m_match_stack.begin() + t_match_start, m_match_stack.end()); + t_t->children.assign(m_match_stack.begin() + static_cast(t_match_start), m_match_stack.end()); + m_match_stack.erase(m_match_stack.begin() + static_cast(t_match_start), m_match_stack.end()); } /// \todo fix the fact that a successful match that captured no ast_nodes doesn't have any real start position @@ -1910,6 +1910,7 @@ namespace chaiscript case(AST_Node_Type::Bitwise_Xor) : case(AST_Node_Type::Bitwise_Or) : case(AST_Node_Type::Comparison) : + assert(m_match_stack.size() > 1); m_match_stack.erase(m_match_stack.begin() + m_match_stack.size() - 2, m_match_stack.begin() + m_match_stack.size() - 1); build_match(std::make_shared(oper->text), prev_stack_top); break; diff --git a/src/main.cpp b/src/main.cpp index dead221..5c3be99 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,7 +8,10 @@ #include #include +#ifdef _MSC_VER #define _CRT_SECURE_NO_WARNINGS +#endif + #include #ifdef READLINE_AVAILABLE @@ -18,7 +21,7 @@ char *mystrdup (const char *s) { size_t len = strlen(s); // Space for length plus nul - char *d = static_cast(malloc (len+1)); + char *d = static_cast(malloc (len+1)); if (d == nullptr) return nullptr; // No memory #ifdef CHAISCRIPT_MSVC strcpy_s(d, len, s); // Copy the characters @@ -152,10 +155,6 @@ void help(int n) { } } -void version(int){ - std::cout << "chai: compiled " << __TIME__ << " " << __DATE__ << '\n'; -} - bool throws_exception(const std::function &f) { try { @@ -214,11 +213,11 @@ std::string get_next_command() { // We have to wrap exit with our own because Clang has a hard time with // function pointers to functions with special attributes (system exit being marked NORETURN) -void myexit(int return_val) { +void myexit [[ noreturn ]] (int return_val) { exit(return_val); } -void interactive(chaiscript::ChaiScript& chai) +void interactive [[ noreturn ]] (chaiscript::ChaiScript& chai) { using_history(); @@ -287,7 +286,6 @@ int main(int argc, char *argv[]) chai.add(chaiscript::fun(&myexit), "exit"); chai.add(chaiscript::fun(&myexit), "quit"); chai.add(chaiscript::fun(&help), "help"); - chai.add(chaiscript::fun(&version), "version"); chai.add(chaiscript::fun(&throws_exception), "throws_exception"); chai.add(chaiscript::fun(&get_eval_error), "get_eval_error"); @@ -317,7 +315,7 @@ int main(int argc, char *argv[]) arg += line + '\n' ; } } else if ( arg == "-v" || arg == "--version" ) { - arg = "version(0)" ; + arg = "version()" ; } else if ( arg == "-h" || arg == "--help" ) { arg = "help(-1)"; } else if ( arg == "-i" || arg == "--interactive" ) { @@ -332,10 +330,14 @@ int main(int argc, char *argv[]) chaiscript::Boxed_Value val ; try { switch ( mode ) { - case eInteractive : interactive(chai); break; - case eCommand : val = chai.eval(arg); break; - case eFile : val = chai.eval_file(arg); break; - default : std::cout << "Unrecognized execution mode\n"; return EXIT_FAILURE; + case eInteractive: + // interactive never returns, no need for break; + interactive(chai); + case eCommand: + val = chai.eval(arg); + break; + case eFile: + val = chai.eval_file(arg); } } catch (const chaiscript::exception::eval_error &ee) { diff --git a/src/test_module.cpp b/src/test_module.cpp index cb95326..aeb1159 100644 --- a/src/test_module.cpp +++ b/src/test_module.cpp @@ -10,6 +10,7 @@ class TestBaseType TestBaseType() : val(10), const_val(15) { } TestBaseType(int) : val(10), const_val(15) {} TestBaseType(int *) : val(10), const_val(15) {} + TestBaseType(const TestBaseType &) = default; virtual ~TestBaseType() {} virtual int func() { return 0; } @@ -62,6 +63,8 @@ class TestDerivedType : public TestBaseType { public: virtual ~TestDerivedType() {} + TestDerivedType(const TestDerivedType &) = default; + TestDerivedType() = default; virtual int func() CHAISCRIPT_OVERRIDE { return 1; } int derived_only_func() { return 19; } @@ -72,6 +75,8 @@ class TestDerivedType : public TestBaseType class TestMoreDerivedType : public TestDerivedType { public: + TestMoreDerivedType(const TestMoreDerivedType &) = default; + TestMoreDerivedType() = default; virtual ~TestMoreDerivedType() {} }; diff --git a/unittests/functor_cast_test.cpp b/unittests/functor_cast_test.cpp index 7c76ca2..5fa388f 100644 --- a/unittests/functor_cast_test.cpp +++ b/unittests/functor_cast_test.cpp @@ -1,6 +1,6 @@ #include -double test_call(const std::function &f, int val) +int test_call(const std::function &f, int val) { return f(val); } @@ -9,15 +9,15 @@ int main() { chaiscript::ChaiScript chai; - + chai.add(chaiscript::fun(&test_call), "test_call"); - chai.eval("def func(i) { return i * 3.5; };"); - double d = chai.eval("test_call(func, 3)"); - - if (d == 3 * 3.5) + chai.eval("def func(i) { return i * 6; };"); + int d = chai.eval("test_call(func, 3)"); + + if (d == 3 * 6) { - return EXIT_SUCCESS; + return EXIT_SUCCESS; } else { return EXIT_FAILURE; } diff --git a/unittests/object_lifetime_test2.cpp b/unittests/object_lifetime_test2.cpp index c99b191..31c5858 100644 --- a/unittests/object_lifetime_test2.cpp +++ b/unittests/object_lifetime_test2.cpp @@ -4,9 +4,9 @@ template struct Vector2 { - Vector2() : x(0), y(0) {}; - Vector2(T px, T py) : x(px), y(py) {}; - Vector2(const Vector2& cp) : x(cp.x), y(cp.y) {}; + Vector2() : x(0), y(0) {} + Vector2(T px, T py) : x(px), y(py) {} + Vector2(const Vector2& cp) : x(cp.x), y(cp.y) {} Vector2& operator+=(const Vector2& vec_r) {