From 12e8e33144ae23283f5b79444b3cf5867c5c7845 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 19 Apr 2018 19:54:03 +0300 Subject: [PATCH] build: enable -Wimplicit-fallthrough warning for OpenCV modules --- 3rdparty/ittnotify/CMakeLists.txt | 2 ++ 3rdparty/libjasper/CMakeLists.txt | 1 + 3rdparty/libjpeg/CMakeLists.txt | 2 +- 3rdparty/libpng/CMakeLists.txt | 2 +- 3rdparty/libtiff/CMakeLists.txt | 1 + 3rdparty/libwebp/CMakeLists.txt | 1 + 3rdparty/openexr/CMakeLists.txt | 1 + 3rdparty/protobuf/CMakeLists.txt | 1 + 3rdparty/zlib/CMakeLists.txt | 1 + cmake/OpenCVCompilerOptions.cmake | 5 ++++- cmake/OpenCVUtils.cmake | 2 +- modules/core/src/persistence.cpp | 5 ++--- modules/core/src/persistence.hpp | 2 +- modules/core/src/persistence_base64.cpp | 2 ++ modules/core/src/softfloat.cpp | 2 ++ modules/imgproc/test/ocl/test_color.cpp | 1 + modules/videoio/src/cap.cpp | 7 +++++++ 17 files changed, 30 insertions(+), 8 deletions(-) diff --git a/3rdparty/ittnotify/CMakeLists.txt b/3rdparty/ittnotify/CMakeLists.txt index 2acb534..c2caf76 100644 --- a/3rdparty/ittnotify/CMakeLists.txt +++ b/3rdparty/ittnotify/CMakeLists.txt @@ -15,6 +15,8 @@ if(NOT WIN32) endif() endif() +ocv_warnings_disable(CMAKE_C_FLAGS -Wimplicit-fallthrough) + ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include") set(ITT_INCLUDE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include") diff --git a/3rdparty/libjasper/CMakeLists.txt b/3rdparty/libjasper/CMakeLists.txt index 29349e0..897b6ae 100644 --- a/3rdparty/libjasper/CMakeLists.txt +++ b/3rdparty/libjasper/CMakeLists.txt @@ -27,6 +27,7 @@ ocv_warnings_disable(CMAKE_C_FLAGS -Wno-implicit-function-declaration -Wno-unini -Wno-unused-but-set-parameter -Wmissing-declarations -Wunused -Wshadow -Wsign-compare -Wstrict-overflow -Wpointer-compare -Wabsolute-value # clang on Linux + -Wimplicit-fallthrough ) ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter -Wstrict-prototypes) # clang ocv_warnings_disable(CMAKE_C_FLAGS /wd4013 /wd4018 /wd4101 /wd4244 /wd4267 /wd4715) # vs2005 diff --git a/3rdparty/libjpeg/CMakeLists.txt b/3rdparty/libjpeg/CMakeLists.txt index 235280a..4d06bbf 100644 --- a/3rdparty/libjpeg/CMakeLists.txt +++ b/3rdparty/libjpeg/CMakeLists.txt @@ -32,7 +32,7 @@ if(CV_GCC OR CV_CLANG) set_source_files_properties(jcdctmgr.c PROPERTIES COMPILE_FLAGS "-O1") endif() -ocv_warnings_disable(CMAKE_C_FLAGS -Wcast-align -Wshadow -Wunused -Wshift-negative-value) +ocv_warnings_disable(CMAKE_C_FLAGS -Wcast-align -Wshadow -Wunused -Wshift-negative-value -Wimplicit-fallthrough) ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter) # clang ocv_warnings_disable(CMAKE_C_FLAGS /wd4013 /wd4244 /wd4267) # vs2005 diff --git a/3rdparty/libpng/CMakeLists.txt b/3rdparty/libpng/CMakeLists.txt index 01ac496..da29029 100644 --- a/3rdparty/libpng/CMakeLists.txt +++ b/3rdparty/libpng/CMakeLists.txt @@ -63,7 +63,7 @@ endif(MSVC) add_library(${PNG_LIBRARY} STATIC ${lib_srcs} ${lib_hdrs}) target_link_libraries(${PNG_LIBRARY} ${ZLIB_LIBRARIES}) -ocv_warnings_disable(CMAKE_C_FLAGS -Wcast-align) +ocv_warnings_disable(CMAKE_C_FLAGS -Wcast-align -Wimplicit-fallthrough) set_target_properties(${PNG_LIBRARY} PROPERTIES OUTPUT_NAME ${PNG_LIBRARY} diff --git a/3rdparty/libtiff/CMakeLists.txt b/3rdparty/libtiff/CMakeLists.txt index c808521..07365ec 100644 --- a/3rdparty/libtiff/CMakeLists.txt +++ b/3rdparty/libtiff/CMakeLists.txt @@ -438,6 +438,7 @@ endif() ocv_warnings_disable(CMAKE_C_FLAGS -Wno-unused-but-set-variable -Wmissing-prototypes -Wmissing-declarations -Wundef -Wunused -Wsign-compare -Wcast-align -Wshadow -Wno-maybe-uninitialized -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -Wmisleading-indentation + -Wimplicit-fallthrough ) ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter) # clang ocv_warnings_disable(CMAKE_CXX_FLAGS -Wmissing-declarations -Wunused-parameter diff --git a/3rdparty/libwebp/CMakeLists.txt b/3rdparty/libwebp/CMakeLists.txt index a2e62bc..cd4d61f 100644 --- a/3rdparty/libwebp/CMakeLists.txt +++ b/3rdparty/libwebp/CMakeLists.txt @@ -37,6 +37,7 @@ endif() ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-variable -Wunused-function -Wshadow -Wmaybe-uninitialized -Wmissing-prototypes # clang -Wmissing-declarations # gcc + -Wimplicit-fallthrough ) ocv_warnings_disable(CMAKE_C_FLAGS /wd4244 /wd4267) # vs2005 diff --git a/3rdparty/openexr/CMakeLists.txt b/3rdparty/openexr/CMakeLists.txt index 5472b6d..34ba6f7 100644 --- a/3rdparty/openexr/CMakeLists.txt +++ b/3rdparty/openexr/CMakeLists.txt @@ -45,6 +45,7 @@ source_group("Src" FILES ${lib_srcs}) ocv_warnings_disable(CMAKE_CXX_FLAGS -Wshadow -Wunused -Wsign-compare -Wundef -Wmissing-declarations -Wuninitialized -Wswitch -Wparentheses -Warray-bounds -Wextra -Wdeprecated-declarations -Wmisleading-indentation -Wdeprecated -Wsuggest-override -Winconsistent-missing-override + -Wimplicit-fallthrough ) ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4018 /wd4099 /wd4100 /wd4101 /wd4127 /wd4189 /wd4245 /wd4305 /wd4389 /wd4512 /wd4701 /wd4702 /wd4706 /wd4800) # vs2005 ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4334) # vs2005 Win64 diff --git a/3rdparty/protobuf/CMakeLists.txt b/3rdparty/protobuf/CMakeLists.txt index 0ebbd11..af106a0 100644 --- a/3rdparty/protobuf/CMakeLists.txt +++ b/3rdparty/protobuf/CMakeLists.txt @@ -21,6 +21,7 @@ else() -Wunused-function -Wunused-const-variable -Wshorten-64-to-32 -Wno-invalid-offsetof -Wenum-compare-switch -Wsuggest-override -Winconsistent-missing-override + -Wimplicit-fallthrough ) endif() if(CV_ICC) diff --git a/3rdparty/zlib/CMakeLists.txt b/3rdparty/zlib/CMakeLists.txt index 8525a11..553700b 100644 --- a/3rdparty/zlib/CMakeLists.txt +++ b/3rdparty/zlib/CMakeLists.txt @@ -82,6 +82,7 @@ set_target_properties(${ZLIB_LIBRARY} PROPERTIES DEFINE_SYMBOL ZLIB_DLL) ocv_warnings_disable(CMAKE_C_FLAGS -Wshorten-64-to-32 -Wattributes -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshift-negative-value -Wundef # _LFS64_LARGEFILE is not defined /wd4267 # MSVS 2015 (x64) + zlib 1.2.11 + -Wimplicit-fallthrough ) set_target_properties(${ZLIB_LIBRARY} PROPERTIES diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake index ae22437..b9293df 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake @@ -119,7 +119,10 @@ if(CV_GCC OR CV_CLANG) add_extra_compiler_option(-Wno-delete-non-virtual-dtor) add_extra_compiler_option(-Wno-unnamed-type-template-args) add_extra_compiler_option(-Wno-comment) - add_extra_compiler_option(-Wno-implicit-fallthrough) + if(NOT OPENCV_SKIP_IMPLICIT_FALLTHROUGH + AND NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES "implicit-fallthrough") + add_extra_compiler_option(-Wimplicit-fallthrough=3) + endif() if(CV_GCC AND CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 7.2.0) add_extra_compiler_option(-Wno-strict-overflow) # Issue is fixed in GCC 7.2.1 endif() diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index 19f05b8..be79111 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -504,7 +504,7 @@ macro(ocv_warnings_disable) foreach(var ${_flag_vars}) foreach(warning ${_gxx_warnings}) if(NOT warning MATCHES "^-Wno-") - string(REPLACE "${warning}" "" ${var} "${${var}}") + string(REGEX REPLACE "${warning}(=[^ ]*)?" "" ${var} "${${var}}") string(REPLACE "-W" "-Wno-" warning "${warning}") endif() ocv_check_flag_support(${var} "${warning}" _varname "") diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index ae6fd3a..a163c28 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -148,9 +148,8 @@ CvGenericHash* cvCreateMap( int flags, int header_size, int elem_size, CvMemStor void icvParseError( CvFileStorage* fs, const char* func_name, const char* err_msg, const char* source_file, int source_line ) { - char buf[1<<10]; - sprintf( buf, "%s(%d): %s", fs->filename, fs->lineno, err_msg ); - cvError( CV_StsParseError, func_name, buf, source_file, source_line ); + cv::String msg = cv::format("%s(%d): %s", fs->filename, fs->lineno, err_msg); + cv::errorNoReturn(cv::Error::StsParseError, func_name, msg.c_str(), source_file, source_line ); } void icvFSCreateCollection( CvFileStorage* fs, int tag, CvFileNode* collection ) diff --git a/modules/core/src/persistence.hpp b/modules/core/src/persistence.hpp index 4d04506..2874e48 100644 --- a/modules/core/src/persistence.hpp +++ b/modules/core/src/persistence.hpp @@ -262,7 +262,7 @@ void icvFSCreateCollection( CvFileStorage* fs, int tag, CvFileNode* collection ) char* icvFSResizeWriteBuffer( CvFileStorage* fs, char* ptr, int len ); int icvCalcStructSize( const char* dt, int initial_size ); int icvCalcElemSize( const char* dt, int initial_size ); -void icvParseError( CvFileStorage* fs, const char* func_name, const char* err_msg, const char* source_file, int source_line ); +void CV_NORETURN icvParseError( CvFileStorage* fs, const char* func_name, const char* err_msg, const char* source_file, int source_line ); char* icvEncodeFormat( int elem_type, char* dt ); int icvDecodeFormat( const char* dt, int* fmt_pairs, int max_len ); int icvDecodeSimpleFormat( const char* dt ); diff --git a/modules/core/src/persistence_base64.cpp b/modules/core/src/persistence_base64.cpp index 90bb1f6..878cc95 100644 --- a/modules/core/src/persistence_base64.cpp +++ b/modules/core/src/persistence_base64.cpp @@ -84,7 +84,9 @@ size_t base64_encode(uint8_t const * src, uint8_t * dst, size_t off, size_t cnt) switch (rst) { case 1U: *dst_cur++ = base64_padding; + /* fallthrough */ case 2U: *dst_cur++ = base64_padding; + /* fallthrough */ default: *dst_cur = 0; break; } diff --git a/modules/core/src/softfloat.cpp b/modules/core/src/softfloat.cpp index 421af31..27a247a 100644 --- a/modules/core/src/softfloat.cpp +++ b/modules/core/src/softfloat.cpp @@ -1098,6 +1098,7 @@ static float32_t f32_roundToInt( float32_t a, uint_fast8_t roundingMode, bool ex switch ( roundingMode ) { case round_near_even: if ( ! fracF32UI( uiA ) ) break; + /* fallthrough */ case round_near_maxMag: if ( exp == 0x7E ) uiZ |= packToF32UI( 0, 0x7F, 0 ); break; @@ -1805,6 +1806,7 @@ static float64_t f64_roundToInt( float64_t a, uint_fast8_t roundingMode, bool ex switch ( roundingMode ) { case round_near_even: if ( ! fracF64UI( uiA ) ) break; + /* fallthrough */ case round_near_maxMag: if ( exp == 0x3FE ) uiZ |= packToF64UI( 0, 0x3FF, 0 ); break; diff --git a/modules/imgproc/test/ocl/test_color.cpp b/modules/imgproc/test/ocl/test_color.cpp index a3a80c7..0d08de0 100644 --- a/modules/imgproc/test/ocl/test_color.cpp +++ b/modules/imgproc/test/ocl/test_color.cpp @@ -103,6 +103,7 @@ PARAM_TEST_CASE(CvtColor, MatDepth, bool) { case COLOR_RGB2HLS: case COLOR_BGR2HLS: h_limit = 180; + /* fallthrough */ case COLOR_RGB2HLS_FULL: case COLOR_BGR2HLS_FULL: { ASSERT_EQ(dst_roi.type(), udst_roi.type()); diff --git a/modules/videoio/src/cap.cpp b/modules/videoio/src/cap.cpp index 7fcbbe8..0e606c3 100644 --- a/modules/videoio/src/cap.cpp +++ b/modules/videoio/src/cap.cpp @@ -60,6 +60,13 @@ #pragma warning(disable: 4748) #endif +#if defined(__clang__) +#pragma clang diagnostic ignored "-Wimplicit-fallthrough" +#endif +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" +#endif + using namespace cv; namespace cv -- 2.7.4