Simplify MSVC warning configuration We've been setting /Wall on MSVC for a while, but /Wall in MSVC is really "all". I.e., it's -Weverything in Clang and GCC, and includes many warnings that are simply diagnostics. MSVC's own headers do not promise to be clean under /Wall. Rather, the equivalent of Clang and GCC's -Wall is /W4, which MSVC does promise to pass. Under /Wall, every new MSVC release we've had to update an ever-growing list of warning exceptions, to disable the off-by-default warnings that were off for a reason. Switch to MSVC's recommendations and just enable /W4. From there, I've trimmed the exception list, now that we don't need to re-disable disabled warnings. A few non-disabled warnings also no longer need exceptions. This should fix the build with VS2022, which was failing due to C5264. C5264 flags a couple of instances in the library, but tons and tons in MSVC headers and googletest. (The instances in the library are a little goofy and reflect things that should have been 'inline constexpr', but we can't rely on C++17 yet. Though I may go add a compat macro for that.) Fixed: 552 Change-Id: I9031c0d5bd4c7a4df1dc3040b38af9cfbcffc06e Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/56045 Auto-Submit: David Benjamin <davidben@google.com> Reviewed-by: Adam Langley <agl@google.com> Commit-Queue: Adam Langley <agl@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ebba93..7e5a648 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -197,67 +197,22 @@ endif() elseif(MSVC) set(MSVC_DISABLED_WARNINGS_LIST - "C4061" # enumerator 'identifier' in switch of enum 'enumeration' is not - # explicitly handled by a case label - # Disable this because it flags even when there is a default. "C4100" # 'exarg' : unreferenced formal parameter "C4127" # conditional expression is constant - "C4200" # nonstandard extension used : zero-sized array in - # struct/union. + # C4204 and C4221 are C89-only restrictions which were dropped in C99, but + # VS2017 warns about it. They can be removed when we require VS2019. "C4204" # nonstandard extension used: non-constant aggregate initializer "C4221" # nonstandard extension used : 'identifier' : cannot be # initialized using address of automatic variable - "C4242" # 'function' : conversion from 'int' to 'uint8_t', - # possible loss of data "C4244" # 'function' : conversion from 'int' to 'uint8_t', # possible loss of data "C4267" # conversion from 'size_t' to 'int', possible loss of data - "C4371" # layout of class may have changed from a previous version of the - # compiler due to better packing of member '...' - "C4388" # signed/unsigned mismatch - "C4296" # '>=' : expression is always true - "C4350" # behavior change: 'std::_Wrap_alloc...' - "C4365" # '=' : conversion from 'size_t' to 'int', - # signed/unsigned mismatch - "C4389" # '!=' : signed/unsigned mismatch - "C4464" # relative include path contains '..' - "C4510" # 'argument' : default constructor could not be generated - "C4512" # 'argument' : assignment operator could not be generated - "C4514" # 'function': unreferenced inline function has been removed - "C4548" # expression before comma has no effect; expected expression with - # side-effect" caused by FD_* macros. - "C4610" # struct 'argument' can never be instantiated - user defined - # constructor required. - "C4623" # default constructor was implicitly defined as deleted - "C4625" # copy constructor could not be generated because a base class - # copy constructor is inaccessible or deleted - "C4626" # assignment operator could not be generated because a base class - # assignment operator is inaccessible or deleted - "C4628" # digraphs not supported with -Ze - "C4668" # 'symbol' is not defined as a preprocessor macro, replacing with - # '0' for 'directives' - # Disable this because GTest uses it everywhere. "C4706" # assignment within conditional expression - "C4710" # 'function': function not inlined - "C4711" # function 'function' selected for inline expansion - "C4800" # 'int' : forcing value to bool 'true' or 'false' - # (performance warning) - "C4820" # 'bytes' bytes padding added after construct 'member_name' - "C5026" # move constructor was implicitly defined as deleted - "C5027" # move assignment operator was implicitly defined as deleted - "C5045" # Compiler will insert Spectre mitigation for memory load if - # /Qspectre switch specified - ) - set(MSVC_LEVEL4_WARNINGS_LIST - # See https://connect.microsoft.com/VisualStudio/feedback/details/1217660/warning-c4265-when-using-functional-header - "C4265" # class has virtual functions, but destructor is not virtual ) string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR ${MSVC_DISABLED_WARNINGS_LIST}) - string(REPLACE "C" " -w4" MSVC_LEVEL4_WARNINGS_STR - ${MSVC_LEVEL4_WARNINGS_LIST}) - set(CMAKE_C_FLAGS "-utf-8 -Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}") - set(CMAKE_CXX_FLAGS "-utf-8 -Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}") + set(CMAKE_C_FLAGS "-utf-8 -W4 -WX ${MSVC_DISABLED_WARNINGS_STR}") + set(CMAKE_CXX_FLAGS "-utf-8 -W4 -WX ${MSVC_DISABLED_WARNINGS_STR}") endif() if(WIN32) @@ -266,10 +221,6 @@ add_definitions(-DNOMINMAX) # Allow use of fopen. add_definitions(-D_CRT_SECURE_NO_WARNINGS) - # VS 2017 and higher supports STL-only warning suppressions. - # A bug in CMake < 3.13.0 may cause the space in this value to - # cause issues when building with NASM. In that case, update CMake. - add_definitions("-D_STL_EXTRA_DISABLED_WARNINGS=4774 4987") endif() # pthread_rwlock_t on Linux requires a feature flag. We limit this to Linux