From afc2c476bb63c4723fc44a1ca0c8d4b481479dd2 Mon Sep 17 00:00:00 2001 From: Ben Lubar Date: Fri, 6 Apr 2018 21:22:48 -0500 Subject: [PATCH] Fix remaining warnings on Windows. --- CMakeLists.txt | 7 +++++- depends/lua/CMakeLists.txt | 2 +- depends/md5/md5wrapper.cpp | 4 --- plugins/Plugins.cmake | 25 ++++++++++-------- plugins/embark-tools.cpp | 6 ++--- plugins/fortplan.cpp | 2 +- plugins/remotefortressreader/CMakeLists.txt | 2 +- plugins/search.cpp | 12 ++++----- plugins/stockpiles/OrganicMatLookup.cpp | 4 +-- plugins/stockpiles/StockpileSerializer.cpp | 28 ++++++++++----------- plugins/stonesense | 2 +- plugins/zone.cpp | 2 +- 12 files changed, 50 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e7d57636f..78790a4f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,13 +53,18 @@ if(MSVC) add_definitions( "/wd4819" ) # Disable use of POSIX name warnings -add_definitions ( "/D_CRT_NONSTDC_NO_WARNINGS") +add_definitions ( "/D_CRT_NONSTDC_NO_WARNINGS /D_CRT_SECURE_NO_WARNINGS") # supress C4503 - VC++ dislikes if a name is too long. If you get # weird and mysterious linking errors, you can disable this, but you'll have to # deal with a LOT of compiler noise over it # see https://msdn.microsoft.com/en-us/library/074af4b6.aspx add_definitions( "/wd4503") + +# suppress C4267 - VC++ complains whenever we implicitly convert an integer to +# a smaller type, and most of the time this is just conversion from 64 to 32 bits +# for things like vector sizes, which are never that big anyway. +add_definitions( "/wd4267") endif() # Automatically detect architecture based on Visual Studio generator diff --git a/depends/lua/CMakeLists.txt b/depends/lua/CMakeLists.txt index 8b9ce8e2e..7dcae8068 100644 --- a/depends/lua/CMakeLists.txt +++ b/depends/lua/CMakeLists.txt @@ -7,7 +7,7 @@ SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DLUA_USE_ ADD_DEFINITIONS(-DLUA_COMPAT_BITLIB) IF(WIN32) - ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE ) + ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE /wd4334 ) ELSE() ADD_DEFINITIONS ( -DLUA_USE_POSIX -DLUA_USE_DLOPEN ) SET ( LIBS m dl ) diff --git a/depends/md5/md5wrapper.cpp b/depends/md5/md5wrapper.cpp index 7feb25035..7e64f7914 100644 --- a/depends/md5/md5wrapper.cpp +++ b/depends/md5/md5wrapper.cpp @@ -16,10 +16,6 @@ * Petr Mrázek */ -#if defined(_MSC_VER) && _MSC_VER >= 1400 -#define _CRT_SECURE_NO_WARNINGS -#endif - //---------------------------------------------------------------------- //basic includes #include diff --git a/plugins/Plugins.cmake b/plugins/Plugins.cmake index 44a8dc5fb..b97db055d 100644 --- a/plugins/Plugins.cmake +++ b/plugins/Plugins.cmake @@ -78,14 +78,6 @@ MACRO(DFHACK_PLUGIN) LIST(APPEND PLUGIN_PROTOS ${CMAKE_CURRENT_SOURCE_DIR}/proto/${pbuf}.proto) ENDFOREACH() - ADD_LIBRARY(${PLUGIN_NAME} MODULE ${PLUGIN_SOURCES}) - IDE_FOLDER(${PLUGIN_NAME} "Plugins") - - ADD_DEPENDENCIES(${PLUGIN_NAME} dfhack-version) - - # Make sure the source is generated before the executable builds. - ADD_DEPENDENCIES(${PLUGIN_NAME} generate_proto) - LIST(LENGTH PLUGIN_PROTOS NUM_PROTO) IF(NUM_PROTO) STRING(REPLACE ".proto" ".pb.cc" PLUGIN_PROTO_SRCS "${PLUGIN_PROTOS}") @@ -106,7 +98,7 @@ MACRO(DFHACK_PLUGIN) ADD_CUSTOM_COMMAND( OUTPUT ${PLUGIN_PROTO_TMP_FILES} COMMAND protoc-bin -I=${CMAKE_CURRENT_SOURCE_DIR}/proto/ - --cpp_out=dllexport_decl=DFHACK_EXPORT:${CMAKE_CURRENT_SOURCE_DIR}/proto/tmp/ + --cpp_out=${CMAKE_CURRENT_SOURCE_DIR}/proto/tmp/ ${PLUGIN_PROTOS} COMMAND ${PERL_EXECUTABLE} ${CMAKE_SOURCE_DIR}/depends/copy-if-different.pl ${PLUGIN_PROTO_TMP_FILES} @@ -120,23 +112,34 @@ MACRO(DFHACK_PLUGIN) ENDIF() ADD_CUSTOM_TARGET(generate_proto_${PLUGIN_NAME} DEPENDS ${PLUGIN_PROTO_TMP_FILES}) - ADD_DEPENDENCIES(${PLUGIN_NAME} generate_proto_${PLUGIN_NAME}) # Merge headers into sources SET_SOURCE_FILES_PROPERTIES( ${PLUGIN_PROTO_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE ) LIST(APPEND PLUGIN_SOURCES ${PLUGIN_PROTO_HDRS}) LIST(APPEND PLUGIN_SOURCES ${PLUGIN_PROTO_SRCS}) - TARGET_LINK_LIBRARIES(${PLUGIN_NAME} dfhack protobuf-lite dfhack-version ${PLUGIN_LINK_LIBRARIES}) IF(UNIX) SET(PLUGIN_COMPILE_FLAGS "${PLUGIN_COMPILE_FLAGS} -include Export.h") ELSE() SET(PLUGIN_COMPILE_FLAGS "${PLUGIN_COMPILE_FLAGS} /FI\"Export.h\"") ENDIF() + ENDIF() + + ADD_LIBRARY(${PLUGIN_NAME} MODULE ${PLUGIN_SOURCES}) + IDE_FOLDER(${PLUGIN_NAME} "Plugins") + + IF(NUM_PROTO) + ADD_DEPENDENCIES(${PLUGIN_NAME} generate_proto_${PLUGIN_NAME}) + TARGET_LINK_LIBRARIES(${PLUGIN_NAME} dfhack protobuf-lite dfhack-version ${PLUGIN_LINK_LIBRARIES}) ELSE() TARGET_LINK_LIBRARIES(${PLUGIN_NAME} dfhack dfhack-version ${PLUGIN_LINK_LIBRARIES}) ENDIF() + ADD_DEPENDENCIES(${PLUGIN_NAME} dfhack-version) + + # Make sure the source is generated before the executable builds. + ADD_DEPENDENCIES(${PLUGIN_NAME} generate_proto) + IF(UNIX) SET(PLUGIN_COMPILE_FLAGS "${PLUGIN_COMPILE_FLAGS} ${PLUGIN_COMPILE_FLAGS_GCC}") ELSE() diff --git a/plugins/embark-tools.cpp b/plugins/embark-tools.cpp index 2358bf95f..34613cafb 100644 --- a/plugins/embark-tools.cpp +++ b/plugins/embark-tools.cpp @@ -286,7 +286,7 @@ protected: // Used for event handling int prev_x; int prev_y; - bool prev_lbut; + int8_t prev_lbut; // Used for controls bool base_max_x; bool base_max_y; @@ -306,7 +306,7 @@ protected: return in_local_move || in_local_edge_resize_x || in_local_edge_resize_y || in_local_corner_resize; } - void lbut_press(start_sitest* screen, bool pressed, int x, int y) + void lbut_press(start_sitest* screen, int8_t pressed, int x, int y) { GET_EMBARK_POS(screen, x1, x2, y1, y2, width, height); in_local_move = in_local_edge_resize_x = in_local_edge_resize_y = @@ -462,7 +462,7 @@ public: :EmbarkTool(), prev_x(0), prev_y(0), - prev_lbut(false), + prev_lbut(0), base_max_x(false), base_max_y(false), in_local_move(false), diff --git a/plugins/fortplan.cpp b/plugins/fortplan.cpp index a1934c4ab..8609cb13c 100644 --- a/plugins/fortplan.cpp +++ b/plugins/fortplan.cpp @@ -165,7 +165,7 @@ command_result fortplan(color_ostream &out, vector & params) { con.print("Loading file '%s'...\n",filename.c_str()); try { layout = tokenizeFile(filename); - } catch (int e) { + } catch (int) { con.print("Could not open the file.\n"); return CR_FAILURE; } diff --git a/plugins/remotefortressreader/CMakeLists.txt b/plugins/remotefortressreader/CMakeLists.txt index 1d022a95f..f47f03c5f 100644 --- a/plugins/remotefortressreader/CMakeLists.txt +++ b/plugins/remotefortressreader/CMakeLists.txt @@ -42,4 +42,4 @@ ELSE(UNIX) ) ENDIF(UNIX) # this makes sure all the stuff is put in proper places and linked to dfhack -DFHACK_PLUGIN(RemoteFortressReader ${PROJECT_SRCS} LINK_LIBRARIES ${PROJECT_LIBS} COMPILE_FLAGS_MSVC "/FI\"Export.h\"" COMPILE_FLAGS_GCC "-include Export.h -Wno-misleading-indentation" ) +DFHACK_PLUGIN(RemoteFortressReader ${PROJECT_SRCS} LINK_LIBRARIES protobuf-lite ${PROJECT_LIBS} COMPILE_FLAGS_MSVC "/FI\"Export.h\"" COMPILE_FLAGS_GCC "-include Export.h -Wno-misleading-indentation" ) diff --git a/plugins/search.cpp b/plugins/search.cpp index ed8934a0c..aca97d4a9 100644 --- a/plugins/search.cpp +++ b/plugins/search.cpp @@ -957,14 +957,14 @@ class animal_trainer_search : public animal_trainer_search_base public: void render() const { - Screen::paintTile(Screen::Pen(186, 8, 0), 14, 2); - Screen::paintTile(Screen::Pen(186, 8, 0), gps->dimx - 14, 2); - Screen::paintTile(Screen::Pen(201, 8, 0), 14, 1); - Screen::paintTile(Screen::Pen(187, 8, 0), gps->dimx - 14, 1); + Screen::paintTile(Screen::Pen('\xBA', 8, 0), 14, 2); + Screen::paintTile(Screen::Pen('\xBA', 8, 0), gps->dimx - 14, 2); + Screen::paintTile(Screen::Pen('\xC9', 8, 0), 14, 1); + Screen::paintTile(Screen::Pen('\xBB', 8, 0), gps->dimx - 14, 1); for (int x = 15; x <= gps->dimx - 15; ++x) { - Screen::paintTile(Screen::Pen(205, 8, 0), x, 1); - Screen::paintTile(Screen::Pen(0, 0, 0), x, 2); + Screen::paintTile(Screen::Pen('\xCD', 8, 0), x, 1); + Screen::paintTile(Screen::Pen('\x00', 0, 0), x, 2); } print_search_option(16, 2); } diff --git a/plugins/stockpiles/OrganicMatLookup.cpp b/plugins/stockpiles/OrganicMatLookup.cpp index ca9670a96..4f1076cd1 100644 --- a/plugins/stockpiles/OrganicMatLookup.cpp +++ b/plugins/stockpiles/OrganicMatLookup.cpp @@ -71,8 +71,8 @@ void OrganicMatLookup::food_build_map ( std::ostream &out ) df::world_raws &raws = world->raws; df::special_mat_table table = raws.mat_table; using df::enums::organic_mat_category::organic_mat_category; - df::enum_traits traits; - for ( int32_t mat_category = traits.first_item_value; mat_category <= traits.last_item_value; ++mat_category ) + using traits = df::enum_traits; + for ( int32_t mat_category = traits::first_item_value; mat_category <= traits::last_item_value; ++mat_category ) { for ( size_t i = 0; i < table.organic_indexes[mat_category].size(); ++i ) { diff --git a/plugins/stockpiles/StockpileSerializer.cpp b/plugins/stockpiles/StockpileSerializer.cpp index 16c240f67..80e438701 100644 --- a/plugins/stockpiles/StockpileSerializer.cpp +++ b/plugins/stockpiles/StockpileSerializer.cpp @@ -227,14 +227,14 @@ void StockpileSerializer::unserialize_list_organic_mat ( FuncReadImport get_valu void StockpileSerializer::serialize_list_item_type ( FuncItemAllowed is_allowed, FuncWriteExport add_value, const std::vector &list ) { using df::enums::item_type::item_type; - df::enum_traits type_traits; - debug() << "item_type size = " << list.size() << " size limit = " << type_traits.last_item_value << " typecasted: " << ( size_t ) type_traits.last_item_value << endl; - for ( size_t i = 0; i <= ( size_t ) type_traits.last_item_value; ++i ) + using type_traits = df::enum_traits; + debug() << "item_type size = " << list.size() << " size limit = " << type_traits::last_item_value << " typecasted: " << ( size_t ) type_traits::last_item_value << endl; + for ( size_t i = 0; i <= ( size_t ) type_traits::last_item_value; ++i ) { if ( list.at ( i ) ) { const item_type type = ( item_type ) ( ( df::enum_traits::base_type ) i ); - std::string r_type ( type_traits.key_table[i+1] ); + std::string r_type ( type_traits::key_table[i+1] ); if ( !is_allowed ( type ) ) continue; add_value ( r_type ); debug() << "item_type key_table[" << i+1 << "] type[" << ( int16_t ) type << "] is " << r_type < quality_traits; + using quality_traits = df::enum_traits; for ( size_t i = 0; i < 7; ++i ) { if ( quality_list[i] ) { - const std::string f_type ( quality_traits.key_table[i] ); + const std::string f_type ( quality_traits::key_table[i] ); add_value ( f_type ); debug() << " quality: " << i << " is " << f_type <set_prepared_meals ( mPile->settings.food.prepared_meals ); using df::enums::organic_mat_category::organic_mat_category; - df::enum_traits traits; - for ( int32_t mat_category = traits.first_item_value; mat_category ; + for ( int32_t mat_category = traits::first_item_value; mat_category traits; + using traits = df::enum_traits; if ( mBuffer.has_food() ) { mPile->settings.flags.bits.food = 1; @@ -784,7 +784,7 @@ void StockpileSerializer::read_food() debug() << " prepared_meals: " << mPile->settings.food.prepared_meals << endl; - for ( int32_t mat_category = traits.first_item_value; mat_category type_traits; + using type_traits = df::enum_traits; for ( size_t i = 0; i < mPile->settings.furniture.type.size(); ++i ) { if ( mPile->settings.furniture.type.at ( i ) ) { - std::string f_type ( type_traits.key_table[i] ); + std::string f_type ( type_traits::key_table[i] ); furniture->add_type ( f_type ); debug() << "furniture_type " << i << " is " << f_type < & parameters) if (p == "race") { race_filter_set = true; } - } catch (const exception& err) { + } catch (const exception&) { return CR_FAILURE; } }