From 927e3487506e56c549e9b8a336157af5248615d0 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 30 Jan 2024 19:12:03 +0100 Subject: [PATCH 01/15] clang_tidy.cmake: added `run-clang-tidy-19` to binaries to look for --- cmake/clang_tidy.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/clang_tidy.cmake b/cmake/clang_tidy.cmake index 4964954a29c..06f65e32a49 100644 --- a/cmake/clang_tidy.cmake +++ b/cmake/clang_tidy.cmake @@ -11,7 +11,7 @@ if(NOT CMAKE_DISABLE_PRECOMPILE_HEADERS) message(STATUS "Cannot use non-Clang compiler with clang-tidy when precompiled headers are enabled - skipping 'run-clang-tidy' target generation") endif() else() - set(RUN_CLANG_TIDY_NAMES run-clang-tidy run-clang-tidy-18 run-clang-tidy-17 run-clang-tidy-16 run-clang-tidy-15 run-clang-tidy-14 run-clang-tidy-13 run-clang-tidy-12 run-clang-tidy-11 run-clang-tidy-10 run-clang-tidy-9 run-clang-tidy-8) + set(RUN_CLANG_TIDY_NAMES run-clang-tidy run-clang-tidy-19 run-clang-tidy-18 run-clang-tidy-17 run-clang-tidy-16 run-clang-tidy-15 run-clang-tidy-14 run-clang-tidy-13 run-clang-tidy-12 run-clang-tidy-11 run-clang-tidy-10 run-clang-tidy-9 run-clang-tidy-8) endif() if(RUN_CLANG_TIDY_NAMES) From 7d66d9b082986e3bddcc712d331968e3c4832d20 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 30 Jan 2024 19:13:17 +0100 Subject: [PATCH 02/15] updated CI to Clang 19 --- .github/workflows/asan.yml | 6 +++--- .github/workflows/clang-tidy.yml | 10 +++++----- .github/workflows/iwyu.yml | 10 +++++----- .github/workflows/tsan.yml | 6 +++--- .github/workflows/ubsan.yml | 6 +++--- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/asan.yml b/.github/workflows/asan.yml index 942f6e454d4..9297b2f2d5e 100644 --- a/.github/workflows/asan.yml +++ b/.github/workflows/asan.yml @@ -49,7 +49,7 @@ jobs: sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 18 + sudo ./llvm.sh 19 - name: Install Qt ${{ env.QT_VERSION }} if: false @@ -71,8 +71,8 @@ jobs: run: | cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=Off -DWITH_QCHART=Off -DUSE_MATCHCOMPILER=Verify -DANALYZE_ADDRESS=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=Off -DDISABLE_DMAKE=On -DFILESDIR= -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache env: - CC: clang-18 - CXX: clang++-18 + CC: clang-19 + CXX: clang++-19 - name: Build cppcheck run: | diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index 27857e09af0..f934f2bb16b 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -37,8 +37,8 @@ jobs: sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 18 - sudo apt-get install -y clang-tidy-18 + sudo ./llvm.sh 19 + sudo apt-get install -y clang-tidy-19 - name: Install Qt ${{ env.QT_VERSION }} uses: jurplel/install-qt-action@v3 @@ -49,14 +49,14 @@ jobs: - name: Verify clang-tidy configuration run: | - clang-tidy-18 --verify-config + clang-tidy-19 --verify-config - name: Prepare CMake run: | cmake -S . -B cmake.output -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DUSE_QT6=On -DWITH_QCHART=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DCPPCHK_GLIBCXX_DEBUG=Off env: - CC: clang-18 - CXX: clang++-18 + CC: clang-19 + CXX: clang++-19 - name: Prepare CMake dependencies run: | diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml index a7d2f253667..2baded1f6cd 100644 --- a/.github/workflows/iwyu.yml +++ b/.github/workflows/iwyu.yml @@ -147,8 +147,8 @@ jobs: sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 18 - sudo apt-get install -y clang-tools-18 + sudo ./llvm.sh 19 + sudo apt-get install -y clang-tools-19 - name: Install Qt ${{ env.QT_VERSION }} uses: jurplel/install-qt-action@v3 @@ -162,8 +162,8 @@ jobs: run: | cmake -S . -B cmake.output -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DUSE_QT6=On -DWITH_QCHART=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCPPCHK_GLIBCXX_DEBUG=Off -DUSE_MATCHCOMPILER=Off -DEXTERNALS_AS_SYSTEM=On env: - CC: clang-18 - CXX: clang++-18 + CC: clang-19 + CXX: clang++-19 - name: Prepare CMake dependencies run: | @@ -180,7 +180,7 @@ jobs: - name: clang-include-cleaner run: | # TODO: run multi-threaded - find $PWD/cli $PWD/lib $PWD/test $PWD/gui -maxdepth 1 -name "*.cpp" | xargs -t -n 1 clang-include-cleaner-18 --print=changes --extra-arg=-w -p cmake.output > clang-include-cleaner.log 2>&1 + find $PWD/cli $PWD/lib $PWD/test $PWD/gui -maxdepth 1 -name "*.cpp" | xargs -t -n 1 clang-include-cleaner-19 --print=changes --extra-arg=-w -p cmake.output > clang-include-cleaner.log 2>&1 - uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/tsan.yml b/.github/workflows/tsan.yml index c9c4c224d34..d18ca317bc9 100644 --- a/.github/workflows/tsan.yml +++ b/.github/workflows/tsan.yml @@ -49,7 +49,7 @@ jobs: sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 18 + sudo ./llvm.sh 19 - name: Install Qt ${{ env.QT_VERSION }} if: false @@ -70,8 +70,8 @@ jobs: run: | cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=Off -DWITH_QCHART=Off -DUSE_MATCHCOMPILER=Verify -DANALYZE_THREAD=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=Off -DDISABLE_DMAKE=On -DFILESDIR= -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache env: - CC: clang-18 - CXX: clang++-18 + CC: clang-19 + CXX: clang++-19 - name: Build cppcheck run: | diff --git a/.github/workflows/ubsan.yml b/.github/workflows/ubsan.yml index b2c57126873..41ff8a62fe8 100644 --- a/.github/workflows/ubsan.yml +++ b/.github/workflows/ubsan.yml @@ -49,7 +49,7 @@ jobs: sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh 18 + sudo ./llvm.sh 19 - name: Install Qt ${{ env.QT_VERSION }} uses: jurplel/install-qt-action@v3 @@ -70,8 +70,8 @@ jobs: run: | cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=ON -DWITH_QCHART=ON -DUSE_MATCHCOMPILER=Verify -DANALYZE_UNDEFINED=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DFILESDIR= -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache env: - CC: clang-18 - CXX: clang++-18 + CC: clang-19 + CXX: clang++-19 - name: Build cppcheck run: | From 08aaee730793ae6cc7005f6cfc30d5a318e7679c Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 12 Feb 2024 02:34:15 +0100 Subject: [PATCH 03/15] fixed `readability-use-std-min-max` clang-tidy warnings --- gui/mainwindow.cpp | 4 +--- gui/resultstree.cpp | 4 ++-- gui/statsdialog.cpp | 5 +++-- gui/threadhandler.cpp | 6 ++---- lib/checkbufferoverrun.cpp | 6 ++---- lib/checkersreport.cpp | 6 +++--- lib/library.cpp | 3 +-- lib/symboldatabase.cpp | 3 +-- 8 files changed, 15 insertions(+), 22 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index a510fbd1233..ab37bca9b49 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -1200,9 +1200,7 @@ QPair MainWindow::getCppcheckSettings() result.standards.setC(mSettings->value(SETTINGS_STD_C, QString()).toString().toStdString()); result.enforcedLang = (Standards::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt(); - if (result.jobs <= 1) { - result.jobs = 1; - } + result.jobs = std::max(result.jobs, 1u); Settings::terminate(false); diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index c5e2b729966..9d1c16d0962 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -33,6 +33,7 @@ #include "threadhandler.h" #include "xmlreportv2.h" +#include #include #include @@ -849,8 +850,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) if (mContextItem && mApplications->getApplicationCount() > 0 && mContextItem->parent()) { //Create an action for the application int defaultApplicationIndex = mApplications->getDefaultApplication(); - if (defaultApplicationIndex < 0) - defaultApplicationIndex = 0; + defaultApplicationIndex = std::max(defaultApplicationIndex, 0); const Application& app = mApplications->getApplication(defaultApplicationIndex); auto *start = new QAction(app.getName(), &menu); if (multipleSelection) diff --git a/gui/statsdialog.cpp b/gui/statsdialog.cpp index e4e19f5a58d..32e71d28c05 100644 --- a/gui/statsdialog.cpp +++ b/gui/statsdialog.cpp @@ -22,6 +22,8 @@ #include "projectfile.h" #include "showtypes.h" +#include + #include "ui_statsdialog.h" #include @@ -409,8 +411,7 @@ QChartView *createChart(const QString &statsFile, const QString &tool) s->attachAxis(axisY); if (const auto *ls = dynamic_cast(s)) { for (QPointF p : ls->points()) { - if (p.y() > maxY) - maxY = p.y(); + maxY = std::max(p.y(), maxY); } } } diff --git a/gui/threadhandler.cpp b/gui/threadhandler.cpp index b6fd53d251f..d69f2db0fed 100644 --- a/gui/threadhandler.cpp +++ b/gui/threadhandler.cpp @@ -23,6 +23,7 @@ #include "resultsview.h" #include "settings.h" +#include #include #include #include @@ -92,10 +93,7 @@ void ThreadHandler::check(const Settings &settings) setThreadCount(settings.jobs); mRunningThreadCount = mThreads.size(); - - if (mResults.getFileCount() < mRunningThreadCount) { - mRunningThreadCount = mResults.getFileCount(); - } + mRunningThreadCount = std::min(mResults.getFileCount(), mRunningThreadCount); QStringList addonsAndTools = mAddonsAndTools; for (const std::string& addon: settings.addons) { diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 144ae310919..204b2b974c2 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -158,13 +158,11 @@ static int getMinFormatStringOutputLength(const std::vector ¶m if (formatString[i] == 's') { // For strings, the length after the dot "%.2s" will limit // the length of the string. - if (parameterLength > maxLen) - parameterLength = maxLen; + parameterLength = std::min(parameterLength, maxLen); } else { // For integers, the length after the dot "%.2d" can // increase required length - if (tempDigits < maxLen) - tempDigits = maxLen; + tempDigits = std::max(tempDigits, maxLen); } } diff --git a/lib/checkersreport.cpp b/lib/checkersreport.cpp index f6b7c2e8c0b..3391a8edfd8 100644 --- a/lib/checkersreport.cpp +++ b/lib/checkersreport.cpp @@ -22,6 +22,7 @@ #include "errortypes.h" #include "settings.h" +#include #include #include #include @@ -151,11 +152,10 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const fout << "Open source checkers" << std::endl; fout << "--------------------" << std::endl; - int maxCheckerSize = 0; + std::size_t maxCheckerSize = 0; for (const auto& checkReq: checkers::allCheckers) { const std::string& checker = checkReq.first; - if (checker.size() > maxCheckerSize) - maxCheckerSize = checker.size(); + maxCheckerSize = std::max(checker.size(), maxCheckerSize); } for (const auto& checkReq: checkers::allCheckers) { const std::string& checker = checkReq.first; diff --git a/lib/library.cpp b/lib/library.cpp index 179bf9c341d..38843731c53 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -1438,8 +1438,7 @@ bool Library::matchArguments(const Token *ftok, const std::string &functionName) int args = 0; int firstOptionalArg = -1; for (const std::pair & argCheck : it->second.argumentChecks) { - if (argCheck.first > args) - args = argCheck.first; + args = std::max(argCheck.first, args); if (argCheck.second.optional && (firstOptionalArg == -1 || firstOptionalArg > argCheck.first)) firstOptionalArg = argCheck.first; diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 9bdff3f622c..00b259b8b66 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1657,8 +1657,7 @@ void SymbolDatabase::createSymbolDatabaseExprIds() // Find highest varId nonneg int maximumVarId = 0; for (const Token* tok = mTokenizer.list.front(); tok; tok = tok->next()) { - if (tok->varId() > maximumVarId) - maximumVarId = tok->varId(); + maximumVarId = std::max(tok->varId(), maximumVarId); } nonneg int id = maximumVarId + 1; // Find incomplete vars that are used in constant context From 4517502afb4f0baa964e46dbd1a4fbfc7d3378e7 Mon Sep 17 00:00:00 2001 From: firewave Date: Sun, 3 Mar 2024 18:40:38 +0100 Subject: [PATCH 04/15] checkother.cpp: fixed `performance-unnecessary-copy-initialization` clang-tidy warning --- lib/checkother.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 7b9791fe8c4..01388c53c93 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1771,7 +1771,7 @@ void CheckOther::constVariableError(const Variable *var, const Function *functio } const std::string vartype(var->isArgument() ? "Parameter" : "Variable"); - const std::string varname(var->name()); + const std::string& varname(var->name()); const std::string ptrRefArray = var->isArray() ? "const array" : (var->isPointer() ? "pointer to const" : "reference to const"); ErrorPath errorPath; From 4a6da4a42bcbad25da7f9f63ced109553af448df Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 4 Mar 2024 01:22:58 +0100 Subject: [PATCH 05/15] disabled `modernize-use-designated-initializers` clang-tidy check for now --- .clang-tidy | 1 + clang-tidy.md | 1 + 2 files changed, 2 insertions(+) diff --git a/.clang-tidy b/.clang-tidy index d5054062dac..19839d435a5 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -48,6 +48,7 @@ Checks: > -modernize-return-braced-init-list, -modernize-type-traits, -modernize-use-auto, + -modernize-use-designated-initializers, -modernize-use-nodiscard, -modernize-use-trailing-return-type, -performance-avoid-endl, diff --git a/clang-tidy.md b/clang-tidy.md index dce24786dcb..ee6b27d56bf 100644 --- a/clang-tidy.md +++ b/clang-tidy.md @@ -126,6 +126,7 @@ We run this separately via `clang-include-cleaner` in the `iwyu.yml` workflow as `bugprone-switch-missing-default-case`
`bugprone-empty-catch`
`readability-avoid-nested-conditional-operator`
+`modernize-use-designated-initializers`
To be evaluated (need to remove exclusion). From acc56ccd8894dbecd849c98f1db75e1f735c92ab Mon Sep 17 00:00:00 2001 From: firewave Date: Sun, 7 Apr 2024 19:31:07 +0200 Subject: [PATCH 06/15] .clang-tidy: disabled `bugprone-unused-return-value` for now --- .clang-tidy | 1 + clang-tidy.md | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 19839d435a5..8d10e670e24 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -30,6 +30,7 @@ Checks: > -bugprone-signed-char-misuse, -bugprone-switch-missing-default-case, -bugprone-unchecked-optional-access, + -bugprone-unused-return-value, -clang-analyzer-*, -concurrency-mt-unsafe, -misc-const-correctness, diff --git a/clang-tidy.md b/clang-tidy.md index ee6b27d56bf..2c890c4d05f 100644 --- a/clang-tidy.md +++ b/clang-tidy.md @@ -125,8 +125,8 @@ We run this separately via `clang-include-cleaner` in the `iwyu.yml` workflow as `performance-noexcept-swap`
`bugprone-switch-missing-default-case`
`bugprone-empty-catch`
-`readability-avoid-nested-conditional-operator`
-`modernize-use-designated-initializers`
+`readability-avoid-nested-conditional-operator`
+`modernize-use-designated-initializers`
To be evaluated (need to remove exclusion). @@ -141,11 +141,12 @@ To be evaluated (need to remove exclusion). `cert-err33-c`
`google-readability-namespace-comments`
`cppcoreguidelines-special-member-functions`
+`bugprone-unused-return-value`
To be evaluated (need to enable explicitly). -`modernize-type-traits`
-`modernize-use-nodiscard`
+`modernize-type-traits`
+`modernize-use-nodiscard`
These apply to codebases which use later standards then C++11 (C++17 is used when building with Qt6) so we cannot simply apply them. From d78b4fa0285a2c1690c5e0b3d5e75667162fdd2d Mon Sep 17 00:00:00 2001 From: firewave Date: Sun, 7 Apr 2024 19:32:04 +0200 Subject: [PATCH 07/15] .clang-tidy: disabled `readability-enum-initial-value` for now --- .clang-tidy | 1 + clang-tidy.md | 1 + 2 files changed, 2 insertions(+) diff --git a/.clang-tidy b/.clang-tidy index 8d10e670e24..66e05bc8677 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -62,6 +62,7 @@ Checks: > -readability-avoid-nested-conditional-operator, -readability-braces-around-statements, -readability-container-data-pointer, + -readability-enum-initial-value, -readability-function-cognitive-complexity, -readability-function-size, -readability-identifier-length, diff --git a/clang-tidy.md b/clang-tidy.md index 2c890c4d05f..55e68de2979 100644 --- a/clang-tidy.md +++ b/clang-tidy.md @@ -127,6 +127,7 @@ We run this separately via `clang-include-cleaner` in the `iwyu.yml` workflow as `bugprone-empty-catch`
`readability-avoid-nested-conditional-operator`
`modernize-use-designated-initializers`
+`readability-enum-initial-value`
To be evaluated (need to remove exclusion). From 27fd7d4e5d4264a24eb74de70fd8d3d07a553f8a Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 23 May 2024 12:11:27 +0200 Subject: [PATCH 08/15] fixed `readability-math-missing-parentheses` clang-tidy warnings --- cli/signalhandler.cpp | 2 +- gui/codeeditor.cpp | 4 ++-- gui/mainwindow.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/signalhandler.cpp b/cli/signalhandler.cpp index 8d67b4a683a..15dda424de0 100644 --- a/cli/signalhandler.cpp +++ b/cli/signalhandler.cpp @@ -50,7 +50,7 @@ // TODO: __USE_DYNAMIC_STACK_SIZE is dependent on the features.h include and not a built-in compiler define, so it might be problematic to depend on it #ifdef __USE_DYNAMIC_STACK_SIZE -static constexpr size_t MYSTACKSIZE = 16*1024+32768; // wild guess about a reasonable buffer +static constexpr size_t MYSTACKSIZE = (16*1024)+32768; // wild guess about a reasonable buffer #else static constexpr size_t MYSTACKSIZE = 16*1024+SIGSTKSZ; // wild guess about a reasonable buffer #endif diff --git a/gui/codeeditor.cpp b/gui/codeeditor.cpp index 07620ea3cec..ecc3575bc26 100644 --- a/gui/codeeditor.cpp +++ b/gui/codeeditor.cpp @@ -368,9 +368,9 @@ int CodeEditor::lineNumberAreaWidth() } #if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) - const int space = 3 + fontMetrics().horizontalAdvance(QLatin1Char('9')) * digits; + const int space = 3 + (fontMetrics().horizontalAdvance(QLatin1Char('9')) * digits); #else - const int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits; + const int space = 3 + (fontMetrics().width(QLatin1Char('9')) * digits); #endif return space; } diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index ab37bca9b49..e73d48d3e53 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -2167,7 +2167,7 @@ static int getVersion(const QString& nameWithVersion) { break; if (c == ' ') { if (ret > 0 && dot == 1 && nameWithVersion.endsWith(" dev")) - return ret * 1000000 + v * 1000 + 500; + return (ret * 1000000) + (v * 1000) + 500; dot = ret = v = 0; } else if (c == '.') { From 58f708c57b0d892665dbce67a3c46c818b55450f Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 23 May 2024 12:12:38 +0200 Subject: [PATCH 09/15] projectfiledialog.cpp: fixed `performance-unnecessary-copy-initialization` clang-tidy warning --- gui/projectfiledialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/projectfiledialog.cpp b/gui/projectfiledialog.cpp index 69babe4007b..bfe67c6b2f6 100644 --- a/gui/projectfiledialog.cpp +++ b/gui/projectfiledialog.cpp @@ -323,7 +323,7 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile) mUI->mBtnSafeClasses->setChecked(projectFile->safeChecks.classes); setExcludedPaths(projectFile->getExcludedPaths()); setLibraries(projectFile->getLibraries()); - const QString platform = projectFile->getPlatform(); + const QString& platform = projectFile->getPlatform(); if (platform.endsWith(".xml")) { int i; for (i = numberOfBuiltinPlatforms; i < mUI->mComboBoxPlatform->count(); ++i) { From b5e7fa6371ab4750d6513f0f4c47e16978db4c18 Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 12 Jun 2024 11:03:13 +0200 Subject: [PATCH 10/15] mitigated `misc-use-internal-linkage` clang-tidy warnings --- lib/symboldatabase.cpp | 4 ++-- test/signal/test-signalhandler.cpp | 8 ++++---- test/signal/test-stacktrace.cpp | 4 ++-- tools/triage/mainwindow.cpp | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 00b259b8b66..f9072947fc4 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -6122,7 +6122,7 @@ const Scope *SymbolDatabase::findScopeByName(const std::string& name) const //--------------------------------------------------------------------------- template ), REQUIRES("T must be a Type class", std::is_convertible )> -S* findRecordInNestedListImpl(S& thisScope, const std::string& name, bool isC, std::set& visited) +static S* findRecordInNestedListImpl(S& thisScope, const std::string& name, bool isC, std::set& visited) { for (S* scope: thisScope.nestedList) { if (scope->className == name && scope->type != Scope::eFunction) @@ -6171,7 +6171,7 @@ Scope* Scope::findRecordInNestedList(const std::string & name, bool isC) //--------------------------------------------------------------------------- template ), REQUIRES("T must be a Type class", std::is_convertible )> -T* findTypeImpl(S& thisScope, const std::string & name) +static T* findTypeImpl(S& thisScope, const std::string & name) { auto it = thisScope.definedTypesMap.find(name); diff --git a/test/signal/test-signalhandler.cpp b/test/signal/test-signalhandler.cpp index 023137c2a91..37f8907faf8 100644 --- a/test/signal/test-signalhandler.cpp +++ b/test/signal/test-signalhandler.cpp @@ -28,23 +28,23 @@ // static functions are omitted from trace -/*static*/ NORETURN void my_assert() +/*static*/ NORETURN void my_assert() // NOLINT(misc-use-internal-linkage) { assert(false); } -/*static*/ NORETURN void my_abort() +/*static*/ NORETURN void my_abort() // NOLINT(misc-use-internal-linkage) { abort(); } -/*static*/ void my_segv() +/*static*/ void my_segv() // NOLINT(misc-use-internal-linkage) { // cppcheck-suppress nullPointer ++*(int*)nullptr; } -/*static*/ void my_fpe() +/*static*/ void my_fpe() // NOLINT(misc-use-internal-linkage) { #if !defined(__APPLE__) feenableexcept(FE_ALL_EXCEPT); // TODO: check result diff --git a/test/signal/test-stacktrace.cpp b/test/signal/test-stacktrace.cpp index dd9a68485c0..8b4a2698433 100644 --- a/test/signal/test-stacktrace.cpp +++ b/test/signal/test-stacktrace.cpp @@ -25,12 +25,12 @@ // static functions are omitted from trace -/*static*/ void my_func_2() +/*static*/ void my_func_2() // NOLINT(misc-use-internal-linkage) { print_stacktrace(stdout, 0, true, -1, true); } -/*static*/ void my_func() +/*static*/ void my_func() // NOLINT(misc-use-internal-linkage) { my_func_2(); } diff --git a/tools/triage/mainwindow.cpp b/tools/triage/mainwindow.cpp index 81a49883ddb..78706dd4737 100644 --- a/tools/triage/mainwindow.cpp +++ b/tools/triage/mainwindow.cpp @@ -61,10 +61,10 @@ class QWidget; -const QString WORK_FOLDER(QDir::homePath() + "/triage"); -const QString DACA2_PACKAGES(QDir::homePath() + "/daca2-packages"); +static const QString WORK_FOLDER(QDir::homePath() + "/triage"); +static const QString DACA2_PACKAGES(QDir::homePath() + "/daca2-packages"); -constexpr int MAX_ERRORS = 100; +static constexpr int MAX_ERRORS = 100; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), From 7b635aa6851cf8fcd6418448e5ce610c333b783c Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 12 Jun 2024 11:04:12 +0200 Subject: [PATCH 11/15] astutils.cpp: fixed `performance-unnecessary-copy-initialization` clang-tidy warning --- lib/astutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 08a0a046cd1..d5db7ab7334 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -464,7 +464,7 @@ bool isTemporary(const Token* tok, const Library* library, bool unknown) if (ftok->type()) return true; if (library) { - std::string returnType = library->returnValueType(ftok); + const std::string& returnType = library->returnValueType(ftok); return !returnType.empty() && returnType.back() != '&'; } return unknown; From abf8c20565726d5cb8875bd63451888e29dc1f6e Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 30 Jul 2024 14:49:00 +0200 Subject: [PATCH 12/15] valueflow.cpp: mitigated `performance-unnecessary-value-param` clang-tidy warnings --- lib/valueflow.cpp | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index f36f8b8ec07..7b77a615e44 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2556,7 +2556,7 @@ struct LifetimeStore { const TokenList& tokenlist, ErrorLogger& errorLogger, const Settings& settings, - Predicate pred, + const Predicate& pred, SourceLocation loc = SourceLocation::current()) { if (!argtok) @@ -2615,7 +2615,7 @@ struct LifetimeStore { const TokenList& tokenlist, ErrorLogger& errorLogger, const Settings& settings, - Predicate pred, + const Predicate& pred, SourceLocation loc = SourceLocation::current()) { if (!argtok) @@ -6117,31 +6117,11 @@ static void valueFlowLibraryFunction(Token *tok, const std::string &returnValue, }); } -template -struct IteratorRange -{ - Iterator mBegin; - Iterator mEnd; - - Iterator begin() const { - return mBegin; - } - - Iterator end() const { - return mEnd; - } -}; - -template -static IteratorRange MakeIteratorRange(Iterator start, Iterator last) -{ - return {start, last}; -} - static void valueFlowSubFunction(const TokenList& tokenlist, SymbolDatabase& symboldatabase, ErrorLogger& errorLogger, const Settings& settings) { int id = 0; - for (const Scope* scope : MakeIteratorRange(symboldatabase.functionScopes.crbegin(), symboldatabase.functionScopes.crend())) { + for (auto I = symboldatabase.functionScopes.crbegin(); I != symboldatabase.functionScopes.crend(); ++I) { + const Scope* scope = *I; const Function* function = scope->function; if (!function) continue; From 7b26fc8bb366001d7e7b478d3537a51423726e79 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 30 Jul 2024 15:06:29 +0200 Subject: [PATCH 13/15] token.cpp: mitigated `performance-unnecessary-value-param` clang-tidy false positive --- lib/token.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/token.cpp b/lib/token.cpp index 5af8884cdef..7dc25a3d58d 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -2030,6 +2030,7 @@ static bool removeContradiction(std::list& values) using ValueIterator = std::list::iterator; template +// NOLINTNEXTLINE(performance-unnecessary-value-param) - false positive static ValueIterator removeAdjacentValues(std::list& values, ValueIterator x, Iterator start, Iterator last) { if (!isAdjacent(*x, **start)) From a630a69a3a12a95f1c2a31544929fc7bea72d5e4 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 30 Jul 2024 16:10:19 +0200 Subject: [PATCH 14/15] valueflow.cpp: fixed `naming-varname` selfcheck warning --- lib/valueflow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 7b77a615e44..11999c79bb6 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -6120,8 +6120,8 @@ static void valueFlowLibraryFunction(Token *tok, const std::string &returnValue, static void valueFlowSubFunction(const TokenList& tokenlist, SymbolDatabase& symboldatabase, ErrorLogger& errorLogger, const Settings& settings) { int id = 0; - for (auto I = symboldatabase.functionScopes.crbegin(); I != symboldatabase.functionScopes.crend(); ++I) { - const Scope* scope = *I; + for (auto it = symboldatabase.functionScopes.crbegin(); it != symboldatabase.functionScopes.crend(); ++it) { + const Scope* scope = *it; const Function* function = scope->function; if (!function) continue; From 276224eb71e22411645372eb82cf1eba6afd5806 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 30 Jul 2024 16:13:04 +0200 Subject: [PATCH 15/15] statsdialog.cpp: suppress `useStlAlgorithm` selfcheck warning --- gui/statsdialog.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/gui/statsdialog.cpp b/gui/statsdialog.cpp index 32e71d28c05..35fb1fef36b 100644 --- a/gui/statsdialog.cpp +++ b/gui/statsdialog.cpp @@ -411,6 +411,7 @@ QChartView *createChart(const QString &statsFile, const QString &tool) s->attachAxis(axisY); if (const auto *ls = dynamic_cast(s)) { for (QPointF p : ls->points()) { + // cppcheck-suppress useStlAlgorithm - this would reduce the readability of the code maxY = std::max(p.y(), maxY); } }