From ef8ed461740892d7a6b1e1daaf65c003a35cc5c8 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 2 Jan 2025 13:02:19 +0100 Subject: [PATCH 1/2] enabled and fixed `-Wcovered-switch-default` Clang warnings --- cmake/compileroptions.cmake | 1 - gui/checkstatistics.cpp | 2 -- gui/mainwindow.cpp | 3 --- gui/resultstree.cpp | 1 - lib/platform.h | 2 -- lib/symboldatabase.cpp | 2 -- 6 files changed, 11 deletions(-) diff --git a/cmake/compileroptions.cmake b/cmake/compileroptions.cmake index 4112ddd2418..b4b3c2e0689 100644 --- a/cmake/compileroptions.cmake +++ b/cmake/compileroptions.cmake @@ -136,7 +136,6 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options_safe(-Wno-unused-exception-parameter) add_compile_options_safe(-Wno-sign-conversion) add_compile_options_safe(-Wno-shadow-field-in-constructor) - add_compile_options_safe(-Wno-covered-switch-default) add_compile_options_safe(-Wno-shorten-64-to-32) add_compile_options_safe(-Wno-implicit-int-conversion) add_compile_options_safe(-Wno-double-promotion) diff --git a/gui/checkstatistics.cpp b/gui/checkstatistics.cpp index 25bee336811..a3ef82df9b0 100644 --- a/gui/checkstatistics.cpp +++ b/gui/checkstatistics.cpp @@ -59,7 +59,6 @@ void CheckStatistics::addItem(const QString &tool, ShowTypes::ShowType type) ::addItem(mInformation, lower); break; case ShowTypes::ShowNone: - default: qDebug() << "Unknown error type - not added to statistics."; break; } @@ -99,7 +98,6 @@ unsigned CheckStatistics::getCount(const QString &tool, ShowTypes::ShowType type case ShowTypes::ShowInformation: return mInformation.value(lower,0); case ShowTypes::ShowNone: - default: qDebug() << "Unknown error type - returning zero statistics."; return 0; } diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 2d71ef5e7c6..19270f1605b 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -1016,9 +1016,6 @@ bool MainWindow::tryLoadLibrary(Library &library, const QString& filename) case Library::ErrorCode::UNKNOWN_ELEMENT: errmsg = tr("Unknown element"); break; - default: - errmsg = tr("Unknown issue"); - break; } if (!error.reason.empty()) errmsg += " '" + QString::fromStdString(error.reason) + "'"; diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 0c8ee2e3101..548103eaa56 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -377,7 +377,6 @@ QString ResultsTree::severityToTranslatedString(Severity severity) return tr("internal"); case Severity::none: - default: return QString(); } } diff --git a/lib/platform.h b/lib/platform.h index 4673c4859e6..5237868de0e 100644 --- a/lib/platform.h +++ b/lib/platform.h @@ -194,8 +194,6 @@ class CPPCHECKLIB Platform { return "unix64"; case Type::File: return "platformFile"; - default: - throw std::runtime_error("unknown platform"); } } diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 1c77a365a1b..525eeb51fdc 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4065,8 +4065,6 @@ static const char* functionTypeToString(FunctionType type) return "Function"; case FunctionType::eLambda: return "Lambda"; - default: - return "Unknown"; } } From 8497fb0f8bfb80264e20a260e574ed75e8a54350 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 26 Jan 2026 09:26:50 +0100 Subject: [PATCH 2/2] use `cppcheck::unreachable()` --- Makefile | 4 ++-- gui/checkstatistics.cpp | 3 +++ gui/resultstree.cpp | 3 +++ lib/platform.h | 2 ++ lib/symboldatabase.cpp | 1 + oss-fuzz/Makefile | 2 +- 6 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 753348c618a..e2431d614d0 100644 --- a/Makefile +++ b/Makefile @@ -625,7 +625,7 @@ $(libcppdir)/pathanalysis.o: lib/pathanalysis.cpp lib/astutils.h lib/config.h li $(libcppdir)/pathmatch.o: lib/pathmatch.cpp lib/config.h lib/path.h lib/pathmatch.h lib/standards.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/pathmatch.cpp -$(libcppdir)/platform.o: lib/platform.cpp externals/tinyxml2/tinyxml2.h lib/config.h lib/mathlib.h lib/path.h lib/platform.h lib/standards.h lib/xml.h +$(libcppdir)/platform.o: lib/platform.cpp externals/tinyxml2/tinyxml2.h lib/config.h lib/mathlib.h lib/path.h lib/platform.h lib/standards.h lib/utils.h lib/xml.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/platform.cpp $(libcppdir)/preprocessor.o: lib/preprocessor.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/checkers.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h @@ -697,7 +697,7 @@ cli/executor.o: cli/executor.cpp cli/executor.h lib/addoninfo.h lib/checkers.h l cli/filelister.o: cli/filelister.cpp cli/filelister.h lib/config.h lib/filesettings.h lib/mathlib.h lib/path.h lib/pathmatch.h lib/platform.h lib/standards.h lib/utils.h $(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/filelister.cpp -cli/main.o: cli/main.cpp cli/cppcheckexecutor.h lib/config.h lib/filesettings.h lib/mathlib.h lib/path.h lib/platform.h lib/standards.h +cli/main.o: cli/main.cpp cli/cppcheckexecutor.h lib/config.h lib/filesettings.h lib/mathlib.h lib/path.h lib/platform.h lib/standards.h lib/utils.h $(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/main.cpp cli/processexecutor.o: cli/processexecutor.cpp cli/executor.h cli/processexecutor.h lib/addoninfo.h lib/check.h lib/checkers.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h diff --git a/gui/checkstatistics.cpp b/gui/checkstatistics.cpp index a3ef82df9b0..54762f1c4fe 100644 --- a/gui/checkstatistics.cpp +++ b/gui/checkstatistics.cpp @@ -18,6 +18,8 @@ #include "checkstatistics.h" +#include "utils.h" + #include #include #include @@ -101,6 +103,7 @@ unsigned CheckStatistics::getCount(const QString &tool, ShowTypes::ShowType type qDebug() << "Unknown error type - returning zero statistics."; return 0; } + cppcheck::unreachable(); } QStringList CheckStatistics::getTools() const diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 548103eaa56..3e5a0b08280 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -32,6 +32,7 @@ #include "showtypes.h" #include "suppressions.h" #include "threadhandler.h" +#include "utils.h" #include "xmlreportv2.h" #include @@ -379,6 +380,8 @@ QString ResultsTree::severityToTranslatedString(Severity severity) case Severity::none: return QString(); } + + cppcheck::unreachable(); } ResultItem *ResultsTree::findFileItem(const QString &name) const diff --git a/lib/platform.h b/lib/platform.h index 5237868de0e..0820672cc47 100644 --- a/lib/platform.h +++ b/lib/platform.h @@ -24,6 +24,7 @@ #include "config.h" #include "mathlib.h" #include "standards.h" +#include "utils.h" #include #include @@ -195,6 +196,7 @@ class CPPCHECKLIB Platform { case Type::File: return "platformFile"; } + cppcheck::unreachable(); } long long unsignedCharMax() const { diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 525eeb51fdc..c7e56ef01a7 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4066,6 +4066,7 @@ static const char* functionTypeToString(FunctionType type) case FunctionType::eLambda: return "Lambda"; } + cppcheck::unreachable(); } static std::string tokenToString(const Token* tok, const Tokenizer& tokenizer) diff --git a/oss-fuzz/Makefile b/oss-fuzz/Makefile index ad7fb641024..1d938116996 100644 --- a/oss-fuzz/Makefile +++ b/oss-fuzz/Makefile @@ -305,7 +305,7 @@ $(libcppdir)/pathanalysis.o: ../lib/pathanalysis.cpp ../lib/astutils.h ../lib/co $(libcppdir)/pathmatch.o: ../lib/pathmatch.cpp ../lib/config.h ../lib/path.h ../lib/pathmatch.h ../lib/standards.h $(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/pathmatch.cpp -$(libcppdir)/platform.o: ../lib/platform.cpp ../externals/tinyxml2/tinyxml2.h ../lib/config.h ../lib/mathlib.h ../lib/path.h ../lib/platform.h ../lib/standards.h ../lib/xml.h +$(libcppdir)/platform.o: ../lib/platform.cpp ../externals/tinyxml2/tinyxml2.h ../lib/config.h ../lib/mathlib.h ../lib/path.h ../lib/platform.h ../lib/standards.h ../lib/utils.h ../lib/xml.h $(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/platform.cpp $(libcppdir)/preprocessor.o: ../lib/preprocessor.cpp ../externals/simplecpp/simplecpp.h ../lib/addoninfo.h ../lib/checkers.h ../lib/config.h ../lib/errorlogger.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/path.h ../lib/platform.h ../lib/preprocessor.h ../lib/settings.h ../lib/standards.h ../lib/suppressions.h ../lib/utils.h