From 77fb49bee25f3b7aad0c87a4ba951715cd9b7228 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 21 Apr 2022 09:04:15 +0200 Subject: [PATCH 01/13] properly suppress clang-tidy warning in importproject.cpp --- cmake/clang_tidy.cmake | 2 +- lib/importproject.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/clang_tidy.cmake b/cmake/clang_tidy.cmake index ecedff05633..27e04bf36af 100644 --- a/cmake/clang_tidy.cmake +++ b/cmake/clang_tidy.cmake @@ -11,7 +11,7 @@ find_program(RUN_CLANG_TIDY NAMES run-clang-tidy run-clang-tidy-13 run-clang-tid message(STATUS "RUN_CLANG_TIDY=${RUN_CLANG_TIDY}") if (RUN_CLANG_TIDY) # disable all compiler warnings since we are just interested in the tidy ones - add_custom_target(run-clang-tidy ${RUN_CLANG_TIDY} -checks=-performance-unnecessary-copy-initialization -p=${CMAKE_BINARY_DIR} -j ${NPROC} -extra-arg=-w -quiet) + add_custom_target(run-clang-tidy ${RUN_CLANG_TIDY} -p=${CMAKE_BINARY_DIR} -j ${NPROC} -extra-arg=-w -quiet) if (BUILD_GUI) add_dependencies(run-clang-tidy gui-build-deps) if (BUILD_TESTS) diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 4446f5ebdd0..179e7e4fc6a 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -150,6 +150,7 @@ static bool simplifyPathWithVariables(std::string &s, std::map &in, std::map &variables) { std::set found; + // NOLINTNEXTLINE(performance-unnecessary-copy-initialization) const std::list copyIn(in); includePaths.clear(); for (const std::string &ipath : copyIn) { From ee7e2465d459aac513f627587591a5d4b3d57779 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 21 Apr 2022 09:04:59 +0200 Subject: [PATCH 02/13] clang_tidy.cmake: fail if any compiler warning is detected - saves us an additional CI step --- 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 27e04bf36af..d2c16170e21 100644 --- a/cmake/clang_tidy.cmake +++ b/cmake/clang_tidy.cmake @@ -11,7 +11,7 @@ find_program(RUN_CLANG_TIDY NAMES run-clang-tidy run-clang-tidy-13 run-clang-tid message(STATUS "RUN_CLANG_TIDY=${RUN_CLANG_TIDY}") if (RUN_CLANG_TIDY) # disable all compiler warnings since we are just interested in the tidy ones - add_custom_target(run-clang-tidy ${RUN_CLANG_TIDY} -p=${CMAKE_BINARY_DIR} -j ${NPROC} -extra-arg=-w -quiet) + add_custom_target(run-clang-tidy ${RUN_CLANG_TIDY} -p=${CMAKE_BINARY_DIR} -j ${NPROC} -quiet) if (BUILD_GUI) add_dependencies(run-clang-tidy gui-build-deps) if (BUILD_TESTS) From 9e584d20002b3abff2de227ac1853654b1171015 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 21 Apr 2022 09:05:23 +0200 Subject: [PATCH 03/13] suppressions.h: fixed -Wdocumentation warning --- lib/suppressions.h | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/suppressions.h b/lib/suppressions.h index c381eb75b7d..360f0f5270a 100644 --- a/lib/suppressions.h +++ b/lib/suppressions.h @@ -210,7 +210,6 @@ class CPPCHECKLIB Suppressions { /** * @brief Marks Inline Suppressions as checked if source line is in the token stream - * @return No return. */ void markUnmatchedInlineSuppressionsAsChecked(const Tokenizer &tokenizer); From 2c12f183378cffc59a16d9950471b2549ec1ed7c Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 21 Apr 2022 09:07:21 +0200 Subject: [PATCH 04/13] fixed -Wshadow warning for testcppchecklibrarydata.cpp::loadCfgFile() --- gui/test/cppchecklibrarydata/testcppchecklibrarydata.cpp | 4 ++-- gui/test/cppchecklibrarydata/testcppchecklibrarydata.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gui/test/cppchecklibrarydata/testcppchecklibrarydata.cpp b/gui/test/cppchecklibrarydata/testcppchecklibrarydata.cpp index 3088b007bca..9732608705c 100644 --- a/gui/test/cppchecklibrarydata/testcppchecklibrarydata.cpp +++ b/gui/test/cppchecklibrarydata/testcppchecklibrarydata.cpp @@ -543,11 +543,11 @@ void TestCppcheckLibraryData::markupValid() } } -void TestCppcheckLibraryData::loadCfgFile(QString filename, CppcheckLibraryData &data, QString &result, bool removeFile) +void TestCppcheckLibraryData::loadCfgFile(QString filename, CppcheckLibraryData &data, QString &res, bool removeFile) { QFile file(filename); QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); - result = data.open(file); + res = data.open(file); file.close(); if (removeFile) { file.remove(); diff --git a/gui/test/cppchecklibrarydata/testcppchecklibrarydata.h b/gui/test/cppchecklibrarydata/testcppchecklibrarydata.h index dfaa0c67407..64cd1d28c4d 100644 --- a/gui/test/cppchecklibrarydata/testcppchecklibrarydata.h +++ b/gui/test/cppchecklibrarydata/testcppchecklibrarydata.h @@ -41,7 +41,7 @@ private slots: void markupValid(); private: - void loadCfgFile(QString filename, CppcheckLibraryData &data, QString &result, bool removeFile = false); + void loadCfgFile(QString filename, CppcheckLibraryData &data, QString &res, bool removeFile = false); void saveCfgFile(QString filename, CppcheckLibraryData &data); CppcheckLibraryData libraryData; From e88de112aca9e91763f5a02e1fc6b3777e6da8da Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 21 Apr 2022 09:16:21 +0200 Subject: [PATCH 05/13] config.h: added `UNUSED` macro --- lib/config.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/config.h b/lib/config.h index 2f3d247cbcb..39d233d96f0 100644 --- a/lib/config.h +++ b/lib/config.h @@ -64,6 +64,15 @@ # define FALLTHROUGH #endif +// unused +#if defined(__GNUC__) \ + || defined(__clang__) \ + || defined(__CPPCHECK__) +# define UNUSED __attribute__((unused)) +#else +# define UNUSED +#endif + #define REQUIRES(msg, ...) class=typename std::enable_if<__VA_ARGS__::value>::type #include From ebc792e40fcd342f87a47aa4a52bd8d6c2ea9285 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 21 Apr 2022 09:16:39 +0200 Subject: [PATCH 06/13] resultstree.cpp: removed unused function --- gui/resultstree.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 1f54a795eb2..c55efde65b7 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -74,11 +74,6 @@ static const char TAGS[] = "tags"; static const int COLUMN_SINCE_DATE = 6; static const int COLUMN_TAGS = 7; -static QString getFunction(QStandardItem *item) -{ - return item->data().toMap().value("function").toString(); -} - ResultsTree::ResultsTree(QWidget * parent) : QTreeView(parent), mSettings(nullptr), From 35cd258fcb8edcc4e558028a062cb700930e6791 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 21 Apr 2022 09:17:26 +0200 Subject: [PATCH 07/13] translationhandler.cpp: avoid -Wunused-function warning --- gui/test/translationhandler/CMakeLists.txt | 2 +- gui/translationhandler.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gui/test/translationhandler/CMakeLists.txt b/gui/test/translationhandler/CMakeLists.txt index 77b1e416830..7fb6aeefc4e 100644 --- a/gui/test/translationhandler/CMakeLists.txt +++ b/gui/test/translationhandler/CMakeLists.txt @@ -7,7 +7,7 @@ add_executable(test-translationhandler ${CMAKE_SOURCE_DIR}/gui/common.cpp ${CMAKE_SOURCE_DIR}/gui/translationhandler.cpp ) -target_include_directories(test-translationhandler PRIVATE ${CMAKE_SOURCE_DIR}/gui) +target_include_directories(test-translationhandler PRIVATE ${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/lib) target_link_libraries(test-translationhandler ${QT_CORE_LIB} ${QT_WIDGETS_LIB} ${QT_TEST_LIB}) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") diff --git a/gui/translationhandler.cpp b/gui/translationhandler.cpp index 64d6567c40c..1da57c28b79 100644 --- a/gui/translationhandler.cpp +++ b/gui/translationhandler.cpp @@ -18,6 +18,7 @@ #include "translationhandler.h" +#include "config.h" #include "common.h" #include @@ -29,7 +30,7 @@ // Provide own translations for standard buttons. This (garbage) code is needed to enforce them to appear in .ts files even after "lupdate gui.pro" -static void unused() +static UNUSED void unused() { Q_UNUSED(QT_TRANSLATE_NOOP("QPlatformTheme", "OK")) Q_UNUSED(QT_TRANSLATE_NOOP("QPlatformTheme", "Cancel")) From afd595bcfe0db1a44f972c94016271cda95675c4 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 21 Apr 2022 09:20:02 +0200 Subject: [PATCH 08/13] resultstree.cpp: avoid -Wdeprecated-declarations warning --- gui/resultstree.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index c55efde65b7..caa80bb7d99 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -812,7 +812,8 @@ void ResultsTree::startApplication(QStandardItem *target, int application) const QString cmdLine = QString("%1 %2").arg(program).arg(params); - bool success = QProcess::startDetached(cmdLine); + // this is reported as deprecated in Qt 5.15.2 but no longer in Qt 6 + bool success = SUPPRESS_DEPRECATED_WARNING(QProcess::startDetached(cmdLine)); if (!success) { QString text = tr("Could not start %1\n\nPlease check the application path and parameters are correct.").arg(program); From 81efa0ffb61bc9da2d08eaa3bde802578a639a4c Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 21 Apr 2022 09:26:05 +0200 Subject: [PATCH 09/13] removed some unnecessary `__cplusplus` preprocessor checks --- lib/config.h | 4 ++-- lib/valueflow.cpp | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/config.h b/lib/config.h index 39d233d96f0..a3a2812159e 100644 --- a/lib/config.h +++ b/lib/config.h @@ -39,7 +39,7 @@ // C++11 noexcept #if (defined(__GNUC__) && (__GNUC__ >= 5)) \ - || (defined(__clang__) && (defined (__cplusplus)) && (__cplusplus >= 201103L)) \ + || defined(__clang__) \ || defined(__CPPCHECK__) # define NOEXCEPT noexcept #else @@ -48,7 +48,7 @@ // C++11 noreturn #if (defined(__GNUC__) && (__GNUC__ >= 5)) \ - || (defined(__clang__) && (defined (__cplusplus)) && (__cplusplus >= 201103L)) \ + || defined(__clang__) \ || defined(__CPPCHECK__) # define NORETURN [[noreturn]] #else diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 39038e549ae..1ca38b67d3d 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -131,13 +131,7 @@ static void bailoutInternal(const std::string& type, TokenList *tokenlist, Error errorLogger->reportErr(errmsg); } -#if (defined __cplusplus) && __cplusplus >= 201103L #define bailout2(type, tokenlist, errorLogger, tok, what) bailoutInternal(type, tokenlist, errorLogger, tok, what, __FILE__, __LINE__, __func__) -#elif (defined __GNUC__) || (defined __clang__) || (defined _MSC_VER) -#define bailout2(type, tokenlist, errorLogger, tok, what) bailoutInternal(type, tokenlist, errorLogger, tok, what, __FILE__, __LINE__, __FUNCTION__) -#else -#define bailout2(type, tokenlist, errorLogger, tok, what) bailoutInternal(type, tokenlist, errorLogger, tok, what, __FILE__, __LINE__, "(valueFlow)") -#endif #define bailout(tokenlist, errorLogger, tok, what) bailout2("valueFlowBailout", tokenlist, errorLogger, tok, what) From a77ef38eca39bd55b2cba982f19812f0920728d2 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 21 Apr 2022 12:36:41 +0200 Subject: [PATCH 10/13] config.h: made `SUPPRESS_WARNING` usable by any code --- lib/config.h | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/config.h b/lib/config.h index a3a2812159e..dbe3aa9088c 100644 --- a/lib/config.h +++ b/lib/config.h @@ -123,6 +123,7 @@ static const std::string emptyString; #define SUPPRESS_DEPRECATED_WARNING(...) SUPPRESS_WARNING("-Wdeprecated", __VA_ARGS__) #define SUPPRESS_FLOAT_EQUAL_WARNING(...) SUPPRESS_WARNING("-Wfloat-equal", __VA_ARGS__) #else +#define SUPPRESS_WARNING(warning, ...) __VA_ARGS__ #define SUPPRESS_DEPRECATED_WARNING(...) __VA_ARGS__ #define SUPPRESS_FLOAT_EQUAL_WARNING(...) __VA_ARGS__ #endif From 836c8f4c70140d45e9f62f9f38793420461ed60f Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 21 Apr 2022 18:17:01 +0200 Subject: [PATCH 11/13] clang-tidy.yml: use clang to generate the compilation database so we have the proper warning flags --- .github/workflows/clang-tidy.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index 1536e16ac3e..484eed2e4c0 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -21,7 +21,7 @@ jobs: - name: Install missing software run: | apt-get update - apt-get install -y cmake g++ make + apt-get install -y cmake clang-13 make apt-get install -y libpcre3-dev apt-get install -y libffi7 # work around missing dependency for Qt install step apt-get install -y clang-tidy-13 @@ -47,12 +47,15 @@ jobs: cd cmake.output cmake -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DWITH_QCHART=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DCPPCHK_GLIBCXX_DEBUG=Off .. cd .. + env: + CC: clang-13 + CXX: clang++-13 - name: Prepare CMake dependencies run: | # make sure the precompiled headers exist - make -C cmake.output lib/CMakeFiles/lib_objs.dir/cmake_pch.hxx.cxx - make -C cmake.output test/CMakeFiles/testrunner.dir/cmake_pch.hxx.cxx + make -C cmake.output/lib cmake_pch.hxx.pch + make -C cmake.output/test cmake_pch.hxx.pch # make sure the auto-generated GUI sources exist make -C cmake.output autogen From 2be910728fe1a97ea37bcba7969982ceaee2ab94 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 29 Apr 2022 22:29:06 +0200 Subject: [PATCH 12/13] oss-fuzz/main.cpp: fixed `-Wmissing-prototypes` warning --- oss-fuzz/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/oss-fuzz/main.cpp b/oss-fuzz/main.cpp index 8567fb5ca3e..0a07db407f1 100644 --- a/oss-fuzz/main.cpp +++ b/oss-fuzz/main.cpp @@ -30,7 +30,9 @@ class DummyErrorLogger : public ErrorLogger { const std::size_t) override {} }; -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataSize) +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataSize); + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataSize) { if (dataSize < 10000) { const std::string code = generateCode2(data, dataSize); From 3de0310fd200b84f22801ef48da5e49d60d47a34 Mon Sep 17 00:00:00 2001 From: firewave Date: Sat, 14 May 2022 19:10:21 +0200 Subject: [PATCH 13/13] astutils.h: fixed `-Wdocumentation` warning --- lib/astutils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/astutils.h b/lib/astutils.h index 184bad41533..12ff0719037 100644 --- a/lib/astutils.h +++ b/lib/astutils.h @@ -315,8 +315,8 @@ bool isAliased(const Variable *var); const Token* getArgumentStart(const Token* ftok); /** Determines the number of arguments - if token is a function call or macro - * @param start token which is supposed to be the function/macro name. - * \return Number of arguments + * @param ftok start token which is supposed to be the function/macro name. + * @return Number of arguments */ int numberOfArguments(const Token* ftok);