From fa86c75a5f14f77d1dfd71dc0b450571c73ef70b Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 11 Oct 2023 00:31:12 +0200 Subject: [PATCH 1/6] iwyu.yml: increased max line length for include-what-you-use to display the whole comment --- .github/workflows/iwyu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml index 1daa54ce203..8d75bc90f12 100644 --- a/.github/workflows/iwyu.yml +++ b/.github/workflows/iwyu.yml @@ -82,7 +82,7 @@ jobs: - name: iwyu_tool run: | PWD=$(pwd) - iwyu_tool -p cmake.output -j $(nproc) -- -w -Xiwyu --mapping_file=$PWD/qt5.imp > iwyu.log + iwyu_tool -p cmake.output -j $(nproc) -- -w -Xiwyu --max_line_length=1024 -Xiwyu --mapping_file=$PWD/qt5.imp > iwyu.log - uses: actions/upload-artifact@v3 if: success() || failure() From b755cc135aff4162e9909d7ce7261aee20d8a30c Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 11 Oct 2023 00:33:47 +0200 Subject: [PATCH 2/6] iwyu.yml: use long comments with include-what-you-use for more context --- .github/workflows/iwyu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml index 8d75bc90f12..32bc110ffd0 100644 --- a/.github/workflows/iwyu.yml +++ b/.github/workflows/iwyu.yml @@ -82,7 +82,7 @@ jobs: - name: iwyu_tool run: | PWD=$(pwd) - iwyu_tool -p cmake.output -j $(nproc) -- -w -Xiwyu --max_line_length=1024 -Xiwyu --mapping_file=$PWD/qt5.imp > iwyu.log + iwyu_tool -p cmake.output -j $(nproc) -- -w -Xiwyu --max_line_length=1024 -Xiwyu --comment_style=long -Xiwyu --mapping_file=$PWD/qt5.imp > iwyu.log - uses: actions/upload-artifact@v3 if: success() || failure() From ce45852aca7636d3ca54540f0c7cc34feb9f45cf Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 11 Oct 2023 00:35:12 +0200 Subject: [PATCH 3/6] iwyu.yml: have quoted includes first with include-what-you-use to match our include order --- .github/workflows/iwyu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml index 32bc110ffd0..311e46031fa 100644 --- a/.github/workflows/iwyu.yml +++ b/.github/workflows/iwyu.yml @@ -82,7 +82,7 @@ jobs: - name: iwyu_tool run: | PWD=$(pwd) - iwyu_tool -p cmake.output -j $(nproc) -- -w -Xiwyu --max_line_length=1024 -Xiwyu --comment_style=long -Xiwyu --mapping_file=$PWD/qt5.imp > iwyu.log + iwyu_tool -p cmake.output -j $(nproc) -- -w -Xiwyu --max_line_length=1024 -Xiwyu --comment_style=long -Xiwyu --quoted_includes_first -Xiwyu --mapping_file=$PWD/qt5.imp > iwyu.log - uses: actions/upload-artifact@v3 if: success() || failure() From 37cbc20c304a9ba81163ecbeed0faf08ff6bbcea Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 11 Oct 2023 00:40:32 +0200 Subject: [PATCH 4/6] iwyu.yml: always display the full includes with include-what-you-use to make it easier to spot false positives --- .github/workflows/iwyu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml index 311e46031fa..abba6f32b3f 100644 --- a/.github/workflows/iwyu.yml +++ b/.github/workflows/iwyu.yml @@ -82,7 +82,7 @@ jobs: - name: iwyu_tool run: | PWD=$(pwd) - iwyu_tool -p cmake.output -j $(nproc) -- -w -Xiwyu --max_line_length=1024 -Xiwyu --comment_style=long -Xiwyu --quoted_includes_first -Xiwyu --mapping_file=$PWD/qt5.imp > iwyu.log + iwyu_tool -p cmake.output -j $(nproc) -- -w -Xiwyu --max_line_length=1024 -Xiwyu --comment_style=long -Xiwyu --quoted_includes_first -Xiwyu --update_comments -Xiwyu --mapping_file=$PWD/qt5.imp > iwyu.log - uses: actions/upload-artifact@v3 if: success() || failure() From 9e53149d000d01ef0c3d546ff4f24393ca7bd286 Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 11 Oct 2023 01:44:50 +0200 Subject: [PATCH 5/6] cleaned up includes based on include-what-you-use --- Makefile | 2 +- cli/cppcheckexecutorsig.cpp | 1 + gui/resultstree.cpp | 1 + gui/resultstree.h | 2 +- gui/showtypes.cpp | 1 + gui/showtypes.h | 4 ++-- lib/astutils.h | 1 + lib/checkio.cpp | 1 + lib/checkio.h | 2 +- lib/checkmemoryleak.cpp | 1 + lib/checkmemoryleak.h | 3 ++- lib/checkstl.cpp | 1 - lib/keywords.cpp | 2 -- lib/library.cpp | 2 +- lib/library.h | 2 +- lib/pathanalysis.cpp | 1 - lib/symboldatabase.cpp | 1 - lib/symboldatabase.h | 1 - lib/tokenize.cpp | 2 +- lib/tokenize.h | 2 +- lib/utils.h | 1 + test/fixture.h | 3 ++- test/testcmdlineparser.cpp | 5 +++++ test/testprocessexecutor.cpp | 1 - test/testsingleexecutor.cpp | 1 - test/teststring.cpp | 2 -- test/testthreadexecutor.cpp | 1 - 27 files changed, 25 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index f5844225c3b..dfe5082d216 100644 --- a/Makefile +++ b/Makefile @@ -833,7 +833,7 @@ test/testsizeof.o: test/testsizeof.cpp lib/addoninfo.h lib/check.h lib/checksize test/teststl.o: test/teststl.cpp lib/addoninfo.h lib/check.h lib/checkstl.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/teststl.cpp -test/teststring.o: test/teststring.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checkstring.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h +test/teststring.o: test/teststring.cpp lib/addoninfo.h lib/check.h lib/checkstring.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/teststring.cpp test/testsummaries.o: test/testsummaries.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/summaries.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h diff --git a/cli/cppcheckexecutorsig.cpp b/cli/cppcheckexecutorsig.cpp index c5347d8e5ac..943b1454aca 100644 --- a/cli/cppcheckexecutorsig.cpp +++ b/cli/cppcheckexecutorsig.cpp @@ -30,6 +30,7 @@ #include #include #include +#include // __USE_DYNAMIC_STACK_SIZE #include #include #include diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index b7ac15602b8..8d54380dbb5 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -23,6 +23,7 @@ #include "common.h" #include "config.h" #include "erroritem.h" +#include "errortypes.h" #include "path.h" #include "projectfile.h" #include "report.h" diff --git a/gui/resultstree.h b/gui/resultstree.h index 53ba0906754..8d855766082 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -20,7 +20,6 @@ #ifndef RESULTSTREE_H #define RESULTSTREE_H -#include "errortypes.h" #include "showtypes.h" #include @@ -40,6 +39,7 @@ class ThreadHandler; class QContextMenuEvent; class QKeyEvent; class QSettings; +enum class Severity; /// @addtogroup GUI /// @{ diff --git a/gui/showtypes.cpp b/gui/showtypes.cpp index d59b708438f..4ece3ae6ab2 100644 --- a/gui/showtypes.cpp +++ b/gui/showtypes.cpp @@ -19,6 +19,7 @@ #include "showtypes.h" #include "common.h" +#include "errortypes.h" #include diff --git a/gui/showtypes.h b/gui/showtypes.h index 3cff501cf3f..96dc45aec3a 100644 --- a/gui/showtypes.h +++ b/gui/showtypes.h @@ -19,10 +19,10 @@ #ifndef SHOWTYPES_H #define SHOWTYPES_H -#include "errortypes.h" - #include +enum class Severity; + /// @addtogroup GUI /// @{ diff --git a/lib/astutils.h b/lib/astutils.h index 111c2a61d86..3677a4ddb68 100644 --- a/lib/astutils.h +++ b/lib/astutils.h @@ -23,6 +23,7 @@ //--------------------------------------------------------------------------- #include +#include #include #include #include diff --git a/lib/checkio.cpp b/lib/checkio.cpp index 583bbc23e0b..55a6c414ab4 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -19,6 +19,7 @@ //--------------------------------------------------------------------------- #include "checkio.h" +#include "errortypes.h" #include "library.h" #include "mathlib.h" #include "platform.h" diff --git a/lib/checkio.h b/lib/checkio.h index 3e9d15bb972..1293bc0de66 100644 --- a/lib/checkio.h +++ b/lib/checkio.h @@ -23,7 +23,6 @@ #include "check.h" #include "config.h" -#include "errortypes.h" #include "tokenize.h" #include @@ -34,6 +33,7 @@ class Settings; class Token; class Variable; class ErrorLogger; +enum class Severity; /// @addtogroup Checks /// @{ diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 57aacdd2faa..2459adb0b6c 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -21,6 +21,7 @@ #include "astutils.h" #include "errorlogger.h" +#include "errortypes.h" #include "library.h" #include "mathlib.h" #include "platform.h" diff --git a/lib/checkmemoryleak.h b/lib/checkmemoryleak.h index ef8e0564c66..20309873c14 100644 --- a/lib/checkmemoryleak.h +++ b/lib/checkmemoryleak.h @@ -34,7 +34,6 @@ #include "check.h" #include "config.h" -#include "errortypes.h" #include "tokenize.h" #include @@ -46,6 +45,8 @@ class Settings; class Token; class Variable; class ErrorLogger; +struct CWE; +enum class Severity; /// @addtogroup Core /// @{ diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index a9f1446e997..b03e55fdcd4 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -41,7 +41,6 @@ #include #include #include -#include #include #include #include diff --git a/lib/keywords.cpp b/lib/keywords.cpp index 192b5faac81..ab4ab92307d 100644 --- a/lib/keywords.cpp +++ b/lib/keywords.cpp @@ -20,8 +20,6 @@ #include "utils.h" -#include - // see https://en.cppreference.com/w/c/keyword #define C90_KEYWORDS \ diff --git a/lib/library.cpp b/lib/library.cpp index 1bd06904d5a..bcf7dab7de0 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -19,6 +19,7 @@ #include "library.h" #include "astutils.h" +#include "errortypes.h" #include "mathlib.h" #include "path.h" #include "symboldatabase.h" @@ -31,7 +32,6 @@ #include #include #include -#include #include #include #include diff --git a/lib/library.h b/lib/library.h index e45683a56f6..e27ca384290 100644 --- a/lib/library.h +++ b/lib/library.h @@ -23,7 +23,6 @@ #include "config.h" #include "mathlib.h" -#include "errortypes.h" #include "standards.h" #include @@ -37,6 +36,7 @@ class Token; class Settings; +enum class Severity; namespace tinyxml2 { class XMLDocument; diff --git a/lib/pathanalysis.cpp b/lib/pathanalysis.cpp index 0404dba58c4..b15bffb95d4 100644 --- a/lib/pathanalysis.cpp +++ b/lib/pathanalysis.cpp @@ -26,7 +26,6 @@ #include #include #include -#include const Scope* PathAnalysis::findOuterScope(const Scope * scope) { diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 100603dd35d..8cebee3a5ff 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -48,7 +48,6 @@ #include #include #include -#include #include #include //--------------------------------------------------------------------------- diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index a7dd7d9c7b3..26f3ed3e775 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -36,7 +36,6 @@ #include #include #include -#include #include #include diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 4766f4add9f..b4e8ef44c7e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -21,6 +21,7 @@ #include "check.h" #include "errorlogger.h" +#include "errortypes.h" #include "library.h" #include "mathlib.h" #include "platform.h" @@ -50,7 +51,6 @@ #include // IWYU pragma: keep #include #include -#include #include #include #include diff --git a/lib/tokenize.h b/lib/tokenize.h index 07b526ca08c..17ae2f5d3c2 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -22,7 +22,6 @@ //--------------------------------------------------------------------------- #include "config.h" -#include "errortypes.h" #include "tokenlist.h" #include @@ -40,6 +39,7 @@ class TemplateSimplifier; class ErrorLogger; class Preprocessor; class VariableMap; +enum class Severity; namespace simplecpp { class TokenList; diff --git a/lib/utils.h b/lib/utils.h index 2ac0df275c9..9b370fbaff3 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -31,6 +31,7 @@ #include #include #include +#include #include struct SelectMapKeys { diff --git a/test/fixture.h b/test/fixture.h index 039a4a2c097..45b97a65be6 100644 --- a/test/fixture.h +++ b/test/fixture.h @@ -24,7 +24,6 @@ #include "color.h" #include "config.h" #include "errorlogger.h" -#include "errortypes.h" #include "library.h" #include "platform.h" #include "settings.h" @@ -39,6 +38,8 @@ class options; class Tokenizer; +enum class Certainty; +enum class Severity; class TestFixture : public ErrorLogger { private: diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index 59fd3776fe2..afb1eab1630 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -16,11 +16,13 @@ * along with this program. If not, see . */ +#include "cmdlinelogger.h" #include "cmdlineparser.h" #include "config.h" #include "cppcheckexecutor.h" #include "errortypes.h" #include "helpers.h" +#include "importproject.h" #include "platform.h" #include "redirect.h" #include "settings.h" @@ -33,8 +35,11 @@ #include #include #include +#include #include +#include #include +#include #include class TestCmdlineParser : public TestFixture { diff --git a/test/testprocessexecutor.cpp b/test/testprocessexecutor.cpp index 94fe7ee8d7b..0bcfb447ef9 100644 --- a/test/testprocessexecutor.cpp +++ b/test/testprocessexecutor.cpp @@ -26,7 +26,6 @@ #include "library.h" #include -#include #include #include #include diff --git a/test/testsingleexecutor.cpp b/test/testsingleexecutor.cpp index a5f6a519e22..054e8a5472b 100644 --- a/test/testsingleexecutor.cpp +++ b/test/testsingleexecutor.cpp @@ -27,7 +27,6 @@ #include "timer.h" #include -#include #include #include #include diff --git a/test/teststring.cpp b/test/teststring.cpp index 57cea1b9773..8d443e215b4 100644 --- a/test/teststring.cpp +++ b/test/teststring.cpp @@ -28,8 +28,6 @@ #include #include -#include - class TestString : public TestFixture { public: TestString() : TestFixture("TestString") {} diff --git a/test/testthreadexecutor.cpp b/test/testthreadexecutor.cpp index 49d2160b3a9..c37223b26ce 100644 --- a/test/testthreadexecutor.cpp +++ b/test/testthreadexecutor.cpp @@ -26,7 +26,6 @@ #include "timer.h" #include -#include #include #include #include From ecb6a75322c43d11ac88bb70860d56389fafe7e9 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 12 Oct 2023 18:20:51 +0200 Subject: [PATCH 6/6] added TODOs on possibly problematic preprocessor checks --- cli/cppcheckexecutorsig.cpp | 4 ++-- lib/config.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cli/cppcheckexecutorsig.cpp b/cli/cppcheckexecutorsig.cpp index 943b1454aca..567b6c79cf8 100644 --- a/cli/cppcheckexecutorsig.cpp +++ b/cli/cppcheckexecutorsig.cpp @@ -30,7 +30,7 @@ #include #include #include -#include // __USE_DYNAMIC_STACK_SIZE +//#include // __USE_DYNAMIC_STACK_SIZE #include #include #include @@ -49,7 +49,7 @@ # include #endif - +// TODO: __USE_DYNAMIC_STACK_SIZE is depedent on the features.h include and not a built-in compiler define, so it might be problematic to depedent on it #ifdef __USE_DYNAMIC_STACK_SIZE static const size_t MYSTACKSIZE = 16*1024+32768; // wild guess about a reasonable buffer #else diff --git a/lib/config.h b/lib/config.h index d6ef3c37dc0..3f98796bee7 100644 --- a/lib/config.h +++ b/lib/config.h @@ -159,6 +159,7 @@ static const std::string emptyString; #define USE_WINDOWS_SEH #endif +// TODO: __GLIBC__ is depedent on the features.h include and not a built-in compiler define, so it might be problematic to depedent on it #if !defined(NO_UNIX_BACKTRACE_SUPPORT) && defined(__GNUC__) && defined(__GLIBC__) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__NetBSD__) && !defined(__SVR4) && !defined(__QNX__) #define USE_UNIX_BACKTRACE_SUPPORT #endif