build: enable -Wimplicit-fallthrough warning for OpenCV modules
authorAlexander Alekhin <alexander.alekhin@intel.com>
Thu, 19 Apr 2018 16:54:03 +0000 (19:54 +0300)
committerAlexander Alekhin <alexander.alekhin@intel.com>
Thu, 19 Apr 2018 16:54:03 +0000 (19:54 +0300)
17 files changed:
3rdparty/ittnotify/CMakeLists.txt
3rdparty/libjasper/CMakeLists.txt
3rdparty/libjpeg/CMakeLists.txt
3rdparty/libpng/CMakeLists.txt
3rdparty/libtiff/CMakeLists.txt
3rdparty/libwebp/CMakeLists.txt
3rdparty/openexr/CMakeLists.txt
3rdparty/protobuf/CMakeLists.txt
3rdparty/zlib/CMakeLists.txt
cmake/OpenCVCompilerOptions.cmake
cmake/OpenCVUtils.cmake
modules/core/src/persistence.cpp
modules/core/src/persistence.hpp
modules/core/src/persistence_base64.cpp
modules/core/src/softfloat.cpp
modules/imgproc/test/ocl/test_color.cpp
modules/videoio/src/cap.cpp

index 2acb534..c2caf76 100644 (file)
@@ -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")
 
index 29349e0..897b6ae 100644 (file)
@@ -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
index 235280a..4d06bbf 100644 (file)
@@ -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
 
index 01ac496..da29029 100644 (file)
@@ -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}
index c808521..07365ec 100644 (file)
@@ -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
index a2e62bc..cd4d61f 100644 (file)
@@ -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
 
index 5472b6d..34ba6f7 100644 (file)
@@ -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
index 0ebbd11..af106a0 100644 (file)
@@ -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)
index 8525a11..553700b 100644 (file)
@@ -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
index ae22437..b9293df 100644 (file)
@@ -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()
index 19f05b8..be79111 100644 (file)
@@ -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 "")
index ae6fd3a..a163c28 100644 (file)
@@ -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 )
index 4d04506..2874e48 100644 (file)
@@ -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 );
index 90bb1f6..878cc95 100644 (file)
@@ -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;
     }
index 421af31..27a247a 100644 (file)
@@ -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;
index a3a80c7..0d08de0 100644 (file)
@@ -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());
index 7fcbbe8..0e606c3 100644 (file)
 #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