From 0de5a7a2660ddce0fff7cf8f852701197b50a665 Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Wed, 23 Sep 2026 13:19:53 +0200 Subject: [PATCH] Enable -Wimplicit-fallthrough --- cmake/OpenCVCompilerOptions.cmake | 1 + modules/core/src/persistence_base64_encoding.cpp | 4 ++-- modules/core/src/softfloat.cpp | 4 ++-- modules/highgui/src/window_gtk.cpp | 4 ++-- modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp | 4 ++-- modules/imgcodecs/src/grfmt_tiff.cpp | 6 +++--- modules/imgproc/src/demosaicing.cpp | 2 +- modules/imgproc/test/ocl/test_color.cpp | 2 +- modules/objdetect/src/chessboard.cpp | 6 +++--- modules/objdetect/test/test_chesscorners.cpp | 2 +- modules/videoio/src/cap_v4l.cpp | 1 + samples/tapi/camshift.cpp | 1 + 12 files changed, 20 insertions(+), 17 deletions(-) diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake index 2a73fdb3b2..0dc2e60f2b 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake @@ -522,6 +522,7 @@ macro(ocv_add_modules_compiler_options) if(${_varname_cxx}) add_compile_options(-Wcast-function-type-strict) endif() + add_compile_options(-Wimplicit-fallthrough) endif() endmacro() diff --git a/modules/core/src/persistence_base64_encoding.cpp b/modules/core/src/persistence_base64_encoding.cpp index ac56304db1..4ed9e58f9c 100644 --- a/modules/core/src/persistence_base64_encoding.cpp +++ b/modules/core/src/persistence_base64_encoding.cpp @@ -185,9 +185,9 @@ size_t base64::base64_encode(const uint8_t *src, uint8_t *dst, size_t off, size_ switch (rst) { case 1U: *dst_cur++ = base64_padding; - /* fallthrough */ + [[fallthrough]]; case 2U: *dst_cur++ = base64_padding; - /* fallthrough */ + [[fallthrough]]; default: *dst_cur = 0; break; } diff --git a/modules/core/src/softfloat.cpp b/modules/core/src/softfloat.cpp index b5ac5d7dc5..93e3a3243b 100644 --- a/modules/core/src/softfloat.cpp +++ b/modules/core/src/softfloat.cpp @@ -1064,7 +1064,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 */ + [[fallthrough]]; case round_near_maxMag: if ( exp == 0x7E ) uiZ |= packToF32UI( 0, 0x7F, 0 ); break; @@ -1772,7 +1772,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 */ + [[fallthrough]]; case round_near_maxMag: if ( exp == 0x3FE ) uiZ |= packToF64UI( 0, 0x3FF, 0 ); break; diff --git a/modules/highgui/src/window_gtk.cpp b/modules/highgui/src/window_gtk.cpp index ff599bb202..2d39d6d42f 100644 --- a/modules/highgui/src/window_gtk.cpp +++ b/modules/highgui/src/window_gtk.cpp @@ -2003,11 +2003,11 @@ static gboolean icvOnMouse( GtkWidget *widget, GdkEvent *event, gpointer user_da break; #endif //GTK_VERSION3_4 case GDK_SCROLL_LEFT: cv_event = cv::EVENT_MOUSEHWHEEL; - /* FALLTHRU */ + [[fallthrough]]; case GDK_SCROLL_UP: flags |= ~0xffff; break; case GDK_SCROLL_RIGHT: cv_event = cv::EVENT_MOUSEHWHEEL; - /* FALLTHRU */ + [[fallthrough]]; case GDK_SCROLL_DOWN: flags |= (((int)1 << 16)); break; default: ; diff --git a/modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp b/modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp index 54ab95c785..ce3337e694 100644 --- a/modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp +++ b/modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp @@ -615,10 +615,10 @@ bool Jpeg2KOpjDecoderBase::readData( Mat& img ) switch (image_->color_space) { case OPJ_CLRSPC_UNKNOWN: - /* FALLTHRU */ + [[fallthrough]]; case OPJ_CLRSPC_UNSPECIFIED: CV_LOG_WARNING(NULL, "OpenJPEG2000: Image has unknown or unspecified color space, SRGB is assumed"); - /* FALLTHRU */ + [[fallthrough]]; case OPJ_CLRSPC_SRGB: decode = decodeSRGBData; break; diff --git a/modules/imgcodecs/src/grfmt_tiff.cpp b/modules/imgcodecs/src/grfmt_tiff.cpp index 31f48d72a0..5c45eb4849 100644 --- a/modules/imgcodecs/src/grfmt_tiff.cpp +++ b/modules/imgcodecs/src/grfmt_tiff.cpp @@ -478,7 +478,7 @@ static void fixOrientationPartial(Mat &img, uint16_t orientation) case ORIENTATION_RIGHTTOP: case ORIENTATION_LEFTBOT: flip(img, img, -1); - /* fall through */ + [[fallthrough]]; case ORIENTATION_LEFTTOP: case ORIENTATION_RIGHTBOT: @@ -1473,7 +1473,7 @@ bool TiffEncoder::writeLibTiff( const std::vector& img_vec, const std::vect { case CV_8U: sample_format = SAMPLEFORMAT_UINT; - /* FALLTHRU */ + [[fallthrough]]; case CV_8S: { bitsPerChannel = 8; @@ -1482,7 +1482,7 @@ bool TiffEncoder::writeLibTiff( const std::vector& img_vec, const std::vect case CV_16U: sample_format = SAMPLEFORMAT_UINT; - /* FALLTHRU */ + [[fallthrough]]; case CV_16S: { bitsPerChannel = 16; diff --git a/modules/imgproc/src/demosaicing.cpp b/modules/imgproc/src/demosaicing.cpp index b268df753c..7aeecc69f6 100644 --- a/modules/imgproc/src/demosaicing.cpp +++ b/modules/imgproc/src/demosaicing.cpp @@ -1776,7 +1776,7 @@ void cv::demosaicing(InputArray _src, OutputArray _dst, int code, int dcn) case COLOR_BayerBG2BGRA: case COLOR_BayerGB2BGRA: case COLOR_BayerRG2BGRA: case COLOR_BayerGR2BGRA: if (dcn <= 0) dcn = 4; - /* fallthrough */ + [[fallthrough]]; case COLOR_BayerBG2BGR: case COLOR_BayerGB2BGR: case COLOR_BayerRG2BGR: case COLOR_BayerGR2BGR: case COLOR_BayerBG2BGR_VNG: case COLOR_BayerGB2BGR_VNG: case COLOR_BayerRG2BGR_VNG: case COLOR_BayerGR2BGR_VNG: { diff --git a/modules/imgproc/test/ocl/test_color.cpp b/modules/imgproc/test/ocl/test_color.cpp index 55401ba73c..3e624ff956 100644 --- a/modules/imgproc/test/ocl/test_color.cpp +++ b/modules/imgproc/test/ocl/test_color.cpp @@ -103,7 +103,7 @@ PARAM_TEST_CASE(CvtColor, MatDepth, bool) { case COLOR_RGB2HLS: case COLOR_BGR2HLS: h_limit = 180; - /* fallthrough */ + [[fallthrough]]; case COLOR_RGB2HLS_FULL: case COLOR_BGR2HLS_FULL: { ASSERT_EQ(dst_roi.type(), udst_roi.type()); diff --git a/modules/objdetect/src/chessboard.cpp b/modules/objdetect/src/chessboard.cpp index d54dde9672..103fcb4aa1 100644 --- a/modules/objdetect/src/chessboard.cpp +++ b/modules/objdetect/src/chessboard.cpp @@ -3048,7 +3048,7 @@ std::vector Chessboard::Board::getContour()const last = 1; break; } - /* fallthrough */ + [[fallthrough]]; case 2: // right if(iter.right(true)) { @@ -3058,7 +3058,7 @@ std::vector Chessboard::Board::getContour()const last = 2; break; } - /* fallthrough */ + [[fallthrough]]; case 3: // bottom if(iter.bottom(true)) { @@ -3068,7 +3068,7 @@ std::vector Chessboard::Board::getContour()const last = 3; break; } - /* fallthrough */ + [[fallthrough]]; case 4: // left if(iter.left(true)) { diff --git a/modules/objdetect/test/test_chesscorners.cpp b/modules/objdetect/test/test_chesscorners.cpp index b4396949ca..5800ce9dc0 100644 --- a/modules/objdetect/test/test_chesscorners.cpp +++ b/modules/objdetect/test/test_chesscorners.cpp @@ -149,7 +149,7 @@ void CV_ChessboardDetectorTest::run( int /*start_from */) { case CHESSBOARD_SB: checkByGeneratorHighAccuracy(); // not supported by CHESSBOARD - /* fallthrough */ + [[fallthrough]]; case CHESSBOARD_PLAIN: checkByGenerator(); if (ts->get_err_code() != cvtest::TS::OK) diff --git a/modules/videoio/src/cap_v4l.cpp b/modules/videoio/src/cap_v4l.cpp index fec246175a..2d8d5fd0ad 100644 --- a/modules/videoio/src/cap_v4l.cpp +++ b/modules/videoio/src/cap_v4l.cpp @@ -1769,6 +1769,7 @@ bool CvCaptureCAM_V4L::controlInfo(int property_id, __u32 &_v4l2id, cv::Range &r break; case CAP_PROP_AUTO_EXPOSURE: range = Range(0, 4); + break; default: break; } diff --git a/samples/tapi/camshift.cpp b/samples/tapi/camshift.cpp index 324e073400..54ec30da38 100644 --- a/samples/tapi/camshift.cpp +++ b/samples/tapi/camshift.cpp @@ -218,6 +218,7 @@ int main(int argc, const char ** argv) break; case 'c': cv::ocl::setUseOpenCL(!cv::ocl::useOpenCL()); + break; default: break; }