From dbd9534bd924654ee9e983e69188c4925b3d897e Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 2 Mar 2014 08:18:36 -0700 Subject: [PATCH] Eliminate warnings on MSVC 2013 Note that this required ignoring a few warnings with pragmas, changing the parameter type and return types of std::string::find functions to size_t from int and a new global warning disable on MSVC. I've managed to avoid global warning disables up to this point in the code, but I don't see a way around the "decorated name too long (C4503)" warning. Closes #100 --- CMakeLists.txt | 14 +++++++---- include/chaiscript/chaiscript_stdlib.hpp | 2 -- .../chaiscript/dispatchkit/bootstrap_stl.hpp | 24 ++++++++++--------- .../dispatchkit/proxy_functions_detail.hpp | 12 ++++++---- .../language/chaiscript_prelude.chai | 12 +++++----- src/main.cpp | 13 ++++++---- 6 files changed, 44 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c122aac..96f4d51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,14 @@ endif() if(MSVC) add_definitions(/W4) add_definitions(/bigobj) + # Note on MSVC compiler flags. + # The code base selective disables warnings as necessary when the compiler is complaining too much + # about something that is perfectly valid, or there is simply no technical way around it + # This particular warning, C4503 is in regards to the decorated names that MSVC generates internally. + # The error did not come up until the move to C++11, but the compiler doesn't give enough information + # to determine where the error is coming from, and the internet provides no real information for + # how to workaround or fix the error. So I'm disabling it globally. + ADD_DEFINITIONS(/wd4503) else() add_definitions(-Wall -Wextra -Wshadow -pedantic ${CPP11_FLAG}) @@ -106,7 +114,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") else () set (EXTRA_LINKER_FLAGS ${CPP11_FLAG}) endif() -else() +elseif(CMAKE_COMPILER_IS_GNUCC) set (EXTRA_LINKER_FLAGS ${CPP11_FLAG}) endif() @@ -153,10 +161,6 @@ endif(CMAKE_HOST_UNIX) list(APPEND LIBS ${READLINE_LIB}) -if (CMAKE_COMPILER_2005) - # vs2005 is a bit too loud about possible loss of data warnings -# ADD_DEFINITIONS(/wd4244) -endif() add_library(chaiscript_stdlib MODULE src/chaiscript_stdlib.cpp) target_link_libraries(chaiscript_stdlib ${LIBS} ${EXTRA_LINKER_FLAGS} ${CMAKE_THREAD_LIBS_INIT}) diff --git a/include/chaiscript/chaiscript_stdlib.hpp b/include/chaiscript/chaiscript_stdlib.hpp index 0fdad69..57f312f 100644 --- a/include/chaiscript/chaiscript_stdlib.hpp +++ b/include/chaiscript/chaiscript_stdlib.hpp @@ -38,7 +38,5 @@ namespace chaiscript }; } - - #endif diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index 034bc83..13b778a 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -266,7 +266,7 @@ namespace chaiscript template ModulePtr container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) { - m->add(fun( std::function( [](const ContainerType *a) { return a->size(); } ) ), "size"); + m->add(fun( std::function( [](const ContainerType *a) { return a->size(); } ) ), "size"); m->add(fun( std::function( [](const ContainerType *a) { return a->empty(); } ) ), "empty"); m->add(fun( std::function( [](ContainerType *a) { a->clear(); } ) ), "clear"); return m; @@ -525,19 +525,19 @@ namespace chaiscript } m->add(fun(&String::push_back), push_back_name); - typedef std::function find_func; + typedef std::function find_func; - m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->find(f, pos); } )), "find"); - m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->rfind(f, pos); } ) ), "rfind"); - m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->find_first_of(f, pos); } ) ), "find_first_of"); - m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->find_last_of(f, pos); } ) ), "find_last_of"); - m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->find_last_not_of(f, pos); } ) ), "find_last_not_of"); - m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->find_first_not_of(f, pos); } ) ), "find_first_not_of"); + m->add(fun(find_func( [](const String *s, const String &f, size_t pos) { return s->find(f, pos); } )), "find"); + m->add(fun(find_func( [](const String *s, const String &f, size_t pos) { return s->rfind(f, pos); } ) ), "rfind"); + m->add(fun(find_func( [](const String *s, const String &f, size_t pos) { return s->find_first_of(f, pos); } ) ), "find_first_of"); + m->add(fun(find_func( [](const String *s, const String &f, size_t pos) { return s->find_last_of(f, pos); } ) ), "find_last_of"); + m->add(fun(find_func( [](const String *s, const String &f, size_t pos) { return s->find_last_not_of(f, pos); } ) ), "find_last_not_of"); + m->add(fun(find_func( [](const String *s, const String &f, size_t pos) { return s->find_first_not_of(f, pos); } ) ), "find_first_not_of"); - m->add(fun( std::function( [](String *s) { return s->clear(); } ) ), "clear"); - m->add(fun( std::function( [](const String *s) { return s->empty(); } ) ), "empty"); - m->add(fun( std::function( [](const String *s) { return s->size(); } ) ), "size"); + m->add(fun( std::function( [](String *s) { return s->clear(); } ) ), "clear"); + m->add(fun( std::function( [](const String *s) { return s->empty(); } ) ), "empty"); + m->add(fun( std::function( [](const String *s) { return s->size(); } ) ), "size"); m->add(fun( std::function( [](const String *s) { return s->c_str(); } ) ), "c_str"); m->add(fun( std::function( [](const String *s) { return s->data(); } ) ), "data"); @@ -551,3 +551,5 @@ namespace chaiscript #endif + + diff --git a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp index 11cda9e..8f1901c 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -106,11 +106,6 @@ namespace chaiscript }; - -#ifdef BOOST_MSVC -#pragma warning(pop) -#endif - /** * Used by Proxy_Function_Impl to determine if it is equivalent to another * Proxy_Function_Impl object. This function is primarly used to prevent @@ -144,12 +139,19 @@ namespace chaiscript template struct Call_Func { +#ifdef CHAISCRIPT_MSVC +#pragma warning(push) +#pragma warning(disable : 4100) /// Disable unreferenced formal parameter warning, which only shows up in MSVC I don't think there's any way around it \todo evaluate this +#endif template static Ret do_call(const std::function &f, const std::vector &, const Dynamic_Cast_Conversions &t_conversions, InnerParams &&... innerparams) { return f(boxed_cast(std::forward(innerparams), &t_conversions)...); } +#ifdef CHAISCRIPT_MSVC +#pragma warning(pop) +#endif }; /** diff --git a/include/chaiscript/language/chaiscript_prelude.chai b/include/chaiscript/language/chaiscript_prelude.chai index 95710ba..7af9a61 100644 --- a/include/chaiscript/language/chaiscript_prelude.chai +++ b/include/chaiscript/language/chaiscript_prelude.chai @@ -455,37 +455,37 @@ def zip(x, y) { # Returns the position of the second value string in the first value string def string::find(substr) : is_type(substr, "string") { - int(find(this, substr, 0)); + find(this, substr, size_t(0)); } # Returns the position of last match of the second value string in the first value string def string::rfind(substr) : is_type(substr, "string") { - int(rfind(this, substr, -1)); + rfind(this, substr, size_t(-1)); } # Returns the position of the first match of elements in the second value string in the first value string def string::find_first_of(list) : is_type(list, "string") { - int(find_first_of(this, list, 0)); + find_first_of(this, list, size_t(0)); } # Returns the position of the last match of elements in the second value string in the first value string def string::find_last_of(list) : is_type(list, "string") { - int(find_last_of(this, list, -1)); + find_last_of(this, list, size_t(-1)); } # Returns the position of the first non-matching element in the second value string in the first value string def string::find_first_not_of(list) : is_type(list, "string") { - int(find_first_not_of(this, list, 0)); + find_first_not_of(this, list, size_t(0)); } # Returns the position of the last non-matching element in the second value string in the first value string def string::find_last_not_of(list) : is_type(list, "string") { - int(find_last_not_of(this, list, -1)); + find_last_not_of(this, list, size_t(-1)); } diff --git a/src/main.cpp b/src/main.cpp index a473894..d633c76 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,10 +17,15 @@ #else char *mystrdup (const char *s) { - char *d = static_cast(malloc (strlen (s) + 1)); // Space for length plus nul - if (d == nullptr) return nullptr; // No memory - strcpy (d,s); // Copy the characters - return d; // Return the new string + size_t len = strlen(s) + 1; // Space for length plus nul + char *d = static_cast(malloc (len)); + if (d == nullptr) return nullptr; // No memory +#ifdef CHAISCRIPT_MSVC + strcpy_s(d, len, s); // Copy the characters +#else + strcpy(d,s); // Copy the characters +#endif + return d; // Return the new string } char* readline(const char* p)