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
This commit is contained in:
parent
daf5480c48
commit
dbd9534bd9
@ -88,6 +88,14 @@ endif()
|
|||||||
if(MSVC)
|
if(MSVC)
|
||||||
add_definitions(/W4)
|
add_definitions(/W4)
|
||||||
add_definitions(/bigobj)
|
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()
|
else()
|
||||||
add_definitions(-Wall -Wextra -Wshadow -pedantic ${CPP11_FLAG})
|
add_definitions(-Wall -Wextra -Wshadow -pedantic ${CPP11_FLAG})
|
||||||
|
|
||||||
@ -106,7 +114,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|||||||
else ()
|
else ()
|
||||||
set (EXTRA_LINKER_FLAGS ${CPP11_FLAG})
|
set (EXTRA_LINKER_FLAGS ${CPP11_FLAG})
|
||||||
endif()
|
endif()
|
||||||
else()
|
elseif(CMAKE_COMPILER_IS_GNUCC)
|
||||||
set (EXTRA_LINKER_FLAGS ${CPP11_FLAG})
|
set (EXTRA_LINKER_FLAGS ${CPP11_FLAG})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -153,10 +161,6 @@ endif(CMAKE_HOST_UNIX)
|
|||||||
list(APPEND LIBS ${READLINE_LIB})
|
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)
|
add_library(chaiscript_stdlib MODULE src/chaiscript_stdlib.cpp)
|
||||||
target_link_libraries(chaiscript_stdlib ${LIBS} ${EXTRA_LINKER_FLAGS} ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries(chaiscript_stdlib ${LIBS} ${EXTRA_LINKER_FLAGS} ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
@ -38,7 +38,5 @@ namespace chaiscript
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ namespace chaiscript
|
|||||||
template<typename ContainerType>
|
template<typename ContainerType>
|
||||||
ModulePtr container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module()))
|
ModulePtr container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module()))
|
||||||
{
|
{
|
||||||
m->add(fun( std::function<int (const ContainerType *)>( [](const ContainerType *a) { return a->size(); } ) ), "size");
|
m->add(fun( std::function<size_t (const ContainerType *)>( [](const ContainerType *a) { return a->size(); } ) ), "size");
|
||||||
m->add(fun( std::function<bool (const ContainerType *)>( [](const ContainerType *a) { return a->empty(); } ) ), "empty");
|
m->add(fun( std::function<bool (const ContainerType *)>( [](const ContainerType *a) { return a->empty(); } ) ), "empty");
|
||||||
m->add(fun( std::function<void (ContainerType *)>( [](ContainerType *a) { a->clear(); } ) ), "clear");
|
m->add(fun( std::function<void (ContainerType *)>( [](ContainerType *a) { a->clear(); } ) ), "clear");
|
||||||
return m;
|
return m;
|
||||||
@ -525,15 +525,15 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
m->add(fun(&String::push_back), push_back_name);
|
m->add(fun(&String::push_back), push_back_name);
|
||||||
|
|
||||||
typedef std::function<int (const String *, const String &, int)> find_func;
|
typedef std::function<size_t (const String *, const String &, size_t)> 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, size_t 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, size_t 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, size_t 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, size_t 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, 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, 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_first_not_of(f, pos); } ) ), "find_first_not_of");
|
||||||
|
|
||||||
m->add(fun( std::function<void (String *)>( [](String *s) { return s->clear(); } ) ), "clear");
|
m->add(fun( std::function<void (String *)>( [](String *s) { return s->clear(); } ) ), "clear");
|
||||||
m->add(fun( std::function<bool (const String *)>( [](const String *s) { return s->empty(); } ) ), "empty");
|
m->add(fun( std::function<bool (const String *)>( [](const String *s) { return s->empty(); } ) ), "empty");
|
||||||
@ -551,3 +551,5 @@ namespace chaiscript
|
|||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -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
|
* Used by Proxy_Function_Impl to determine if it is equivalent to another
|
||||||
* Proxy_Function_Impl object. This function is primarly used to prevent
|
* Proxy_Function_Impl object. This function is primarly used to prevent
|
||||||
@ -144,12 +139,19 @@ namespace chaiscript
|
|||||||
template<typename Ret, typename ... Params>
|
template<typename Ret, typename ... Params>
|
||||||
struct Call_Func<Ret, 0, Params...>
|
struct Call_Func<Ret, 0, Params...>
|
||||||
{
|
{
|
||||||
|
#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<typename ... InnerParams>
|
template<typename ... InnerParams>
|
||||||
static Ret do_call(const std::function<Ret (Params...)> &f,
|
static Ret do_call(const std::function<Ret (Params...)> &f,
|
||||||
const std::vector<Boxed_Value> &, const Dynamic_Cast_Conversions &t_conversions, InnerParams &&... innerparams)
|
const std::vector<Boxed_Value> &, const Dynamic_Cast_Conversions &t_conversions, InnerParams &&... innerparams)
|
||||||
{
|
{
|
||||||
return f(boxed_cast<Params>(std::forward<InnerParams>(innerparams), &t_conversions)...);
|
return f(boxed_cast<Params>(std::forward<InnerParams>(innerparams), &t_conversions)...);
|
||||||
}
|
}
|
||||||
|
#ifdef CHAISCRIPT_MSVC
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -455,37 +455,37 @@ def zip(x, y) {
|
|||||||
|
|
||||||
# Returns the position of the second value string in the first value string
|
# Returns the position of the second value string in the first value string
|
||||||
def string::find(substr) : is_type(substr, "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
|
# Returns the position of last match of the second value string in the first value string
|
||||||
def string::rfind(substr) : is_type(substr, "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
|
# 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") {
|
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
|
# 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") {
|
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
|
# 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") {
|
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
|
# 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") {
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,9 +17,14 @@
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
char *mystrdup (const char *s) {
|
char *mystrdup (const char *s) {
|
||||||
char *d = static_cast<char*>(malloc (strlen (s) + 1)); // Space for length plus nul
|
size_t len = strlen(s) + 1; // Space for length plus nul
|
||||||
|
char *d = static_cast<char*>(malloc (len));
|
||||||
if (d == nullptr) return nullptr; // No memory
|
if (d == nullptr) return nullptr; // No memory
|
||||||
strcpy (d,s); // Copy the characters
|
#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
|
return d; // Return the new string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user