From 19363ac23eb10dd0d9d73212f4ff77a43217252c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 6 Nov 2021 16:48:31 +0100 Subject: [PATCH] - project contortions to make MSVC print our own deprecations but silence the ones from the compiler. Since everything uses the same warning number, the old setup resulted in [[deprecated]] being silenced. So this explicitly adds the needed #defines to silence the very noisy warning from the MSVC headers but leaves warning 4996 active otherwise. In particlular this does: * silence all warnings in the subprojects * do not derive TIterator from std::iterator anymore as C++17 deprecates this. * silence the above for RapidJSON because altering that code is not desirable. * explicitly disable warning 4996 in some Windows files that call the deprecated (but still needed) GetVersionEx function. * define _CRT_SECURE_NO_DEPRECATE, _CRT_SECURE_NO_WARNINGS and _CRT_NONSTDC_NO_WARNINGS through CMake to disable the CRT's deprecation and security warnings. Currently this will print several (intended) deprecation warnings about 'updatesector' that point to code that needs to be changed but cannot yet without other refactorings being done first. --- CMakeLists.txt | 2 +- libraries/bzip2/CMakeLists.txt | 4 ++++ libraries/glslang/glslang/CMakeLists.txt | 4 ++++ libraries/jpeg/CMakeLists.txt | 4 ++++ source/common/platform/win32/hardware.cpp | 4 ++-- source/common/platform/win32/i_crash.cpp | 1 + source/common/platform/win32/i_system.cpp | 1 + source/common/thirdparty/rapidjson/document.h | 1 + source/common/utility/tarray.h | 12 ++++++------ tools/lemon/CMakeLists.txt | 4 ++++ tools/re2c/CMakeLists.txt | 2 +- 11 files changed, 29 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f504a55d3..249113a75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -236,7 +236,7 @@ if( MSVC ) set( DEB_C_FLAGS "/D _CRTDBG_MAP_ALLOC /MTd" ) # Disable warnings for unsecure CRT functions from VC8+ - set( ALL_C_FLAGS "${ALL_C_FLAGS} /DUNICODE /D_UNICODE /D_WIN32_WINNT=0x0600 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS" ) + set( ALL_C_FLAGS "${ALL_C_FLAGS} /DUNICODE /D_UNICODE /D_WIN32_WINNT=0x0600 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_WARNINGS" ) # These must be silenced because the code is full of them. Expect some of undefined behavior hidden in this mess. :( #set( ALL_C_FLAGS "${ALL_C_FLAGS} /wd4244 /wd4018 /wd4267" ) diff --git a/libraries/bzip2/CMakeLists.txt b/libraries/bzip2/CMakeLists.txt index 6ca7a4e6d..452954c8a 100644 --- a/libraries/bzip2/CMakeLists.txt +++ b/libraries/bzip2/CMakeLists.txt @@ -2,6 +2,10 @@ cmake_minimum_required( VERSION 3.1.0 ) make_release_only() +if (MSVC) + set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4244" ) +endif() + add_definitions( -DBZ_NO_STDIO ) add_library( bz2 STATIC blocksort.c diff --git a/libraries/glslang/glslang/CMakeLists.txt b/libraries/glslang/glslang/CMakeLists.txt index 30b57c588..3ca4c1ce4 100644 --- a/libraries/glslang/glslang/CMakeLists.txt +++ b/libraries/glslang/glslang/CMakeLists.txt @@ -21,6 +21,10 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over. endif() +if (MSVC) + set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4146" ) +endif() + # Request C++11 if(${CMAKE_VERSION} VERSION_LESS 3.1) # CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD diff --git a/libraries/jpeg/CMakeLists.txt b/libraries/jpeg/CMakeLists.txt index 40bc7004b..43ecdac39 100644 --- a/libraries/jpeg/CMakeLists.txt +++ b/libraries/jpeg/CMakeLists.txt @@ -6,6 +6,10 @@ if( DEM_CMAKE_COMPILER_IS_GNUC_COMPATIBLE ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter -fomit-frame-pointer" ) endif() +if (MSVC) + set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4267" ) +endif() + add_library( jpeg STATIC jaricom.c jcomapi.c diff --git a/source/common/platform/win32/hardware.cpp b/source/common/platform/win32/hardware.cpp index 3cadc1ced..13e799594 100644 --- a/source/common/platform/win32/hardware.cpp +++ b/source/common/platform/win32/hardware.cpp @@ -111,9 +111,9 @@ void I_InitGraphics () // todo: implement ATI version of this. this only works for nvidia notebooks, for now. currentgpuswitch = vid_gpuswitch; if (currentgpuswitch == 1) - putenv("SHIM_MCCOMPAT=0x800000001"); // discrete + _putenv("SHIM_MCCOMPAT=0x800000001"); // discrete else if (currentgpuswitch == 2) - putenv("SHIM_MCCOMPAT=0x800000000"); // integrated + _putenv("SHIM_MCCOMPAT=0x800000000"); // integrated // If the focus window is destroyed, it doesn't go back to the active window. // (e.g. because the net pane was up, and a button on it had focus) diff --git a/source/common/platform/win32/i_crash.cpp b/source/common/platform/win32/i_crash.cpp index 90c0658f1..df2a6241e 100644 --- a/source/common/platform/win32/i_crash.cpp +++ b/source/common/platform/win32/i_crash.cpp @@ -34,6 +34,7 @@ // HEADER FILES ------------------------------------------------------------ +#pragma warning(disable:4996) #define WIN32_LEAN_AND_MEAN #include #include diff --git a/source/common/platform/win32/i_system.cpp b/source/common/platform/win32/i_system.cpp index 1de30932d..0ec546567 100644 --- a/source/common/platform/win32/i_system.cpp +++ b/source/common/platform/win32/i_system.cpp @@ -45,6 +45,7 @@ // HEADER FILES ------------------------------------------------------------ +#pragma warning(disable:4996) #include #include #include diff --git a/source/common/thirdparty/rapidjson/document.h b/source/common/thirdparty/rapidjson/document.h index 19f5a6a5f..7612801b5 100644 --- a/source/common/thirdparty/rapidjson/document.h +++ b/source/common/thirdparty/rapidjson/document.h @@ -29,6 +29,7 @@ RAPIDJSON_DIAG_PUSH #ifdef _MSC_VER RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant RAPIDJSON_DIAG_OFF(4244) // conversion from kXxxFlags to 'uint16_t', possible loss of data +RAPIDJSON_DIAG_OFF(4996) // deprecation of std::iterator #endif #ifdef __clang__ diff --git a/source/common/utility/tarray.h b/source/common/utility/tarray.h index 4a9e7388b..b73f43b98 100644 --- a/source/common/utility/tarray.h +++ b/source/common/utility/tarray.h @@ -63,14 +63,14 @@ #include "m_alloc.h" -template class TIterator : public std::iterator +template class TIterator { public: - typedef typename TIterator::value_type value_type; - typedef typename TIterator::difference_type difference_type; - typedef typename TIterator::pointer pointer; - typedef typename TIterator::reference reference; - typedef typename TIterator::iterator_category iterator_category; + typedef typename T value_type; + typedef typename ptrdiff_t difference_type; + typedef typename T* pointer; + typedef typename T& reference; + typedef typename std::random_access_iterator_tag iterator_category; TIterator(T* ptr = nullptr) { m_ptr = ptr; } diff --git a/tools/lemon/CMakeLists.txt b/tools/lemon/CMakeLists.txt index 71418eda5..52551248d 100644 --- a/tools/lemon/CMakeLists.txt +++ b/tools/lemon/CMakeLists.txt @@ -3,6 +3,10 @@ cmake_minimum_required( VERSION 3.1.0 ) if( NOT CMAKE_CROSSCOMPILING ) set( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG" ) +if (MSVC) + set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4244 /wd4267" ) +endif() + add_executable( lemon lemon.c ) set( CROSS_EXPORTS ${CROSS_EXPORTS} lemon PARENT_SCOPE ) diff --git a/tools/re2c/CMakeLists.txt b/tools/re2c/CMakeLists.txt index 9fcfef5a2..1fd3cd5d8 100644 --- a/tools/re2c/CMakeLists.txt +++ b/tools/re2c/CMakeLists.txt @@ -7,7 +7,7 @@ include( CheckTypeSize ) if( MSVC ) # Runtime type information is required and don't complain about uint32_t to bool conversions - set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR /wd4800" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR /wd4800 /wd4244" ) endif() set( PACKAGE_NAME re2c )