MSVC: lower C4100 warning level from 4 to 3

The C4100 warning is related to unused formal parameters in functions.

Enabling it better aligns with "-Wunused-parameter" option in other
compilers.

While suppressing it with `__pragma(warning(suppress:4100))` is not the
same as using `__attribute__((__unused__))` in GCC or Clang, it is
still preferable to use it over completely hiding the warning.

This ensures consistent warning behavior across compilers and improves
code quality by addressing unused function parameters.

(Note that some warnings in Windows-specific code have already been
silenced in 7fcb262dfd)

Pull Request: blender/blender#105534
This commit is contained in:
2023-03-09 16:05:48 +01:00
committed by Germano Cavalcante
parent 85fb63f99c
commit f27d6b9640
8 changed files with 29 additions and 1 deletions

View File

@@ -1607,6 +1607,7 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
# warning level: # warning level:
"/W3" "/W3"
"/w34062" # switch statement contains 'default' but no 'case' labels "/w34062" # switch statement contains 'default' but no 'case' labels
"/w34100" # 'identifier' : unreferenced formal parameter
"/w34115" # 'type' : named type definition in parentheses "/w34115" # 'type' : named type definition in parentheses
"/w34189" # local variable is initialized but not referenced "/w34189" # local variable is initialized but not referenced
# see https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/c5038?view=vs-2017 # see https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/c5038?view=vs-2017

View File

@@ -702,6 +702,7 @@ macro(remove_strict_flags)
endif() endif()
if(MSVC) if(MSVC)
remove_cc_flag(/w34100) # Restore warn C4100 (unreferenced formal parameter) back to w4
remove_cc_flag(/w34189) # Restore warn C4189 (unused variable) back to w4 remove_cc_flag(/w34189) # Restore warn C4189 (unused variable) back to w4
endif() endif()
@@ -721,7 +722,7 @@ macro(remove_extra_strict_flags)
endif() endif()
if(MSVC) if(MSVC)
# TODO remove_cc_flag(/w34100) # Restore warn C4100 (unreferenced formal parameter) back to w4
endif() endif()
endmacro() endmacro()

View File

@@ -10,6 +10,9 @@
#ifdef __GNUC__ #ifdef __GNUC__
# define UNUSED(x) UNUSED_##x __attribute__((__unused__)) # define UNUSED(x) UNUSED_##x __attribute__((__unused__))
#elif defined(_MSC_VER)
/* NOTE: This suppresses the warning for the line, not the attribute. */
# define UNUSED(x) UNUSED_##x __pragma(warning(suppress : 4100))
#else #else
# define UNUSED(x) UNUSED_##x # define UNUSED(x) UNUSED_##x
#endif #endif

View File

@@ -15,6 +15,13 @@ if(WIN32)
add_definitions(-D_USE_MATH_DEFINES) add_definitions(-D_USE_MATH_DEFINES)
endif() endif()
if(WIN32)
# Some files in extern are being included which brings up a bunch of
# "unreferenced formal parameter" warnings.
# So restore warn C4100 (unreferenced formal parameter) back to w4
remove_cc_flag(/w34100)
endif()
set(INC set(INC
extern extern

View File

@@ -668,6 +668,9 @@ extern bool BLI_memory_is_zero(const void *arr, size_t arr_size);
/* UNUSED macro, for function argument */ /* UNUSED macro, for function argument */
# if defined(__GNUC__) || defined(__clang__) # if defined(__GNUC__) || defined(__clang__)
# define UNUSED(x) UNUSED_##x __attribute__((__unused__)) # define UNUSED(x) UNUSED_##x __attribute__((__unused__))
# elif defined(_MSC_VER)
/* NOTE: This suppresses the warning for the line, not the attribute. */
# define UNUSED(x) UNUSED_##x __pragma(warning(suppress : 4100))
# else # else
# define UNUSED(x) UNUSED_##x # define UNUSED(x) UNUSED_##x
# endif # endif

View File

@@ -35,6 +35,13 @@ if(USD_IMAGING_HEADERS)
add_definitions(-DUSD_HAS_IMAGING) add_definitions(-DUSD_HAS_IMAGING)
endif() endif()
if(WIN32)
# Some USD library headers trigger the "unreferenced formal parameter"
# warning alert.
# Silence them by restore warn C4100 back to w4
remove_cc_flag(/w34100)
endif()
set(INC set(INC
. .
../common ../common

View File

@@ -140,6 +140,9 @@ if(CMAKE_COMPILER_IS_GNUCC OR (CMAKE_C_COMPILER_ID MATCHES "Clang"))
endif() endif()
if(CMAKE_C_COMPILER_ID MATCHES "Clang") if(CMAKE_C_COMPILER_ID MATCHES "Clang")
string(APPEND GENSRC_CFLAGS " -Wno-missing-variable-declarations") string(APPEND GENSRC_CFLAGS " -Wno-missing-variable-declarations")
elseif(MSVC)
# Restore warn C4100 (unreferenced formal parameter) back to w4
remove_cc_flag(/w34100)
endif() endif()
if(GENSRC_CFLAGS) if(GENSRC_CFLAGS)

View File

@@ -12,6 +12,9 @@
#if defined(__GNUC__) || defined(__clang__) #if defined(__GNUC__) || defined(__clang__)
# pragma GCC diagnostic error "-Wmissing-prototypes" # pragma GCC diagnostic error "-Wmissing-prototypes"
# pragma GCC diagnostic ignored "-Wunused-parameter" # pragma GCC diagnostic ignored "-Wunused-parameter"
#elif defined(_MSC_VER)
/* Suppress unreferenced formal parameter warning. */
# pragma warning(disable : 4100)
#endif #endif
/* python, will come back */ /* python, will come back */