Skip to content

Commit dbd9534

Browse files
committed
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
1 parent daf5480 commit dbd9534

6 files changed

Lines changed: 44 additions & 33 deletions

File tree

CMakeLists.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ endif()
8888
if(MSVC)
8989
add_definitions(/W4)
9090
add_definitions(/bigobj)
91+
# Note on MSVC compiler flags.
92+
# The code base selective disables warnings as necessary when the compiler is complaining too much
93+
# about something that is perfectly valid, or there is simply no technical way around it
94+
# This particular warning, C4503 is in regards to the decorated names that MSVC generates internally.
95+
# The error did not come up until the move to C++11, but the compiler doesn't give enough information
96+
# to determine where the error is coming from, and the internet provides no real information for
97+
# how to workaround or fix the error. So I'm disabling it globally.
98+
ADD_DEFINITIONS(/wd4503)
9199
else()
92100
add_definitions(-Wall -Wextra -Wshadow -pedantic ${CPP11_FLAG})
93101

@@ -106,7 +114,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
106114
else ()
107115
set (EXTRA_LINKER_FLAGS ${CPP11_FLAG})
108116
endif()
109-
else()
117+
elseif(CMAKE_COMPILER_IS_GNUCC)
110118
set (EXTRA_LINKER_FLAGS ${CPP11_FLAG})
111119
endif()
112120

@@ -153,10 +161,6 @@ endif(CMAKE_HOST_UNIX)
153161
list(APPEND LIBS ${READLINE_LIB})
154162

155163

156-
if (CMAKE_COMPILER_2005)
157-
# vs2005 is a bit too loud about possible loss of data warnings
158-
# ADD_DEFINITIONS(/wd4244)
159-
endif()
160164

161165
add_library(chaiscript_stdlib MODULE src/chaiscript_stdlib.cpp)
162166
target_link_libraries(chaiscript_stdlib ${LIBS} ${EXTRA_LINKER_FLAGS} ${CMAKE_THREAD_LIBS_INIT})

include/chaiscript/chaiscript_stdlib.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,5 @@ namespace chaiscript
3838
};
3939
}
4040

41-
42-
4341
#endif
4442

include/chaiscript/dispatchkit/bootstrap_stl.hpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ namespace chaiscript
266266
template<typename ContainerType>
267267
ModulePtr container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module()))
268268
{
269-
m->add(fun( std::function<int (const ContainerType *)>( [](const ContainerType *a) { return a->size(); } ) ), "size");
269+
m->add(fun( std::function<size_t (const ContainerType *)>( [](const ContainerType *a) { return a->size(); } ) ), "size");
270270
m->add(fun( std::function<bool (const ContainerType *)>( [](const ContainerType *a) { return a->empty(); } ) ), "empty");
271271
m->add(fun( std::function<void (ContainerType *)>( [](ContainerType *a) { a->clear(); } ) ), "clear");
272272
return m;
@@ -525,19 +525,19 @@ namespace chaiscript
525525
}
526526
m->add(fun(&String::push_back), push_back_name);
527527

528-
typedef std::function<int (const String *, const String &, int)> find_func;
528+
typedef std::function<size_t (const String *, const String &, size_t)> find_func;
529529

530530

531-
m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->find(f, pos); } )), "find");
532-
m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->rfind(f, pos); } ) ), "rfind");
533-
m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->find_first_of(f, pos); } ) ), "find_first_of");
534-
m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->find_last_of(f, pos); } ) ), "find_last_of");
535-
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");
536-
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");
531+
m->add(fun(find_func( [](const String *s, const String &f, size_t pos) { return s->find(f, pos); } )), "find");
532+
m->add(fun(find_func( [](const String *s, const String &f, size_t pos) { return s->rfind(f, pos); } ) ), "rfind");
533+
m->add(fun(find_func( [](const String *s, const String &f, size_t pos) { return s->find_first_of(f, pos); } ) ), "find_first_of");
534+
m->add(fun(find_func( [](const String *s, const String &f, size_t pos) { return s->find_last_of(f, pos); } ) ), "find_last_of");
535+
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");
536+
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");
537537

538-
m->add(fun( std::function<void (String *)>( [](String *s) { return s->clear(); } ) ), "clear");
539-
m->add(fun( std::function<bool (const String *)>( [](const String *s) { return s->empty(); } ) ), "empty");
540-
m->add(fun( std::function<size_t (const String *)>( [](const String *s) { return s->size(); } ) ), "size");
538+
m->add(fun( std::function<void (String *)>( [](String *s) { return s->clear(); } ) ), "clear");
539+
m->add(fun( std::function<bool (const String *)>( [](const String *s) { return s->empty(); } ) ), "empty");
540+
m->add(fun( std::function<size_t (const String *)>( [](const String *s) { return s->size(); } ) ), "size");
541541

542542
m->add(fun( std::function<const char *(const String *)>( [](const String *s) { return s->c_str(); } ) ), "c_str");
543543
m->add(fun( std::function<const char *(const String *)>( [](const String *s) { return s->data(); } ) ), "data");
@@ -551,3 +551,5 @@ namespace chaiscript
551551

552552

553553
#endif
554+
555+

include/chaiscript/dispatchkit/proxy_functions_detail.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,6 @@ namespace chaiscript
106106
};
107107

108108

109-
110-
#ifdef BOOST_MSVC
111-
#pragma warning(pop)
112-
#endif
113-
114109
/**
115110
* Used by Proxy_Function_Impl to determine if it is equivalent to another
116111
* Proxy_Function_Impl object. This function is primarly used to prevent
@@ -144,12 +139,19 @@ namespace chaiscript
144139
template<typename Ret, typename ... Params>
145140
struct Call_Func<Ret, 0, Params...>
146141
{
142+
#ifdef CHAISCRIPT_MSVC
143+
#pragma warning(push)
144+
#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
145+
#endif
147146
template<typename ... InnerParams>
148147
static Ret do_call(const std::function<Ret (Params...)> &f,
149148
const std::vector<Boxed_Value> &, const Dynamic_Cast_Conversions &t_conversions, InnerParams &&... innerparams)
150149
{
151150
return f(boxed_cast<Params>(std::forward<InnerParams>(innerparams), &t_conversions)...);
152151
}
152+
#ifdef CHAISCRIPT_MSVC
153+
#pragma warning(pop)
154+
#endif
153155
};
154156

155157
/**

include/chaiscript/language/chaiscript_prelude.chai

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -455,37 +455,37 @@ def zip(x, y) {
455455

456456
# Returns the position of the second value string in the first value string
457457
def string::find(substr) : is_type(substr, "string") {
458-
int(find(this, substr, 0));
458+
find(this, substr, size_t(0));
459459
}
460460

461461

462462
# Returns the position of last match of the second value string in the first value string
463463
def string::rfind(substr) : is_type(substr, "string") {
464-
int(rfind(this, substr, -1));
464+
rfind(this, substr, size_t(-1));
465465
}
466466

467467

468468
# Returns the position of the first match of elements in the second value string in the first value string
469469
def string::find_first_of(list) : is_type(list, "string") {
470-
int(find_first_of(this, list, 0));
470+
find_first_of(this, list, size_t(0));
471471
}
472472

473473

474474
# Returns the position of the last match of elements in the second value string in the first value string
475475
def string::find_last_of(list) : is_type(list, "string") {
476-
int(find_last_of(this, list, -1));
476+
find_last_of(this, list, size_t(-1));
477477
}
478478

479479

480480
# Returns the position of the first non-matching element in the second value string in the first value string
481481
def string::find_first_not_of(list) : is_type(list, "string") {
482-
int(find_first_not_of(this, list, 0));
482+
find_first_not_of(this, list, size_t(0));
483483
}
484484

485485

486486
# Returns the position of the last non-matching element in the second value string in the first value string
487487
def string::find_last_not_of(list) : is_type(list, "string") {
488-
int(find_last_not_of(this, list, -1));
488+
find_last_not_of(this, list, size_t(-1));
489489
}
490490

491491

src/main.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@
1717
#else
1818

1919
char *mystrdup (const char *s) {
20-
char *d = static_cast<char*>(malloc (strlen (s) + 1)); // Space for length plus nul
21-
if (d == nullptr) return nullptr; // No memory
22-
strcpy (d,s); // Copy the characters
23-
return d; // Return the new string
20+
size_t len = strlen(s) + 1; // Space for length plus nul
21+
char *d = static_cast<char*>(malloc (len));
22+
if (d == nullptr) return nullptr; // No memory
23+
#ifdef CHAISCRIPT_MSVC
24+
strcpy_s(d, len, s); // Copy the characters
25+
#else
26+
strcpy(d,s); // Copy the characters
27+
#endif
28+
return d; // Return the new string
2429
}
2530

2631
char* readline(const char* p)

0 commit comments

Comments
 (0)