diff --git a/.clang-tidy b/.clang-tidy
index e1bae2cd255..96c8908f0c0 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -45,7 +45,6 @@ Checks: >
-modernize-replace-auto-ptr,
-modernize-return-braced-init-list,
-modernize-use-auto,
- -modernize-use-equals-default,
-modernize-use-trailing-return-type,
-performance-avoid-endl,
-performance-inefficient-string-concatenation,
@@ -57,7 +56,6 @@ Checks: >
-readability-braces-around-statements,
-readability-const-return-type,
-readability-container-data-pointer,
- -readability-container-size-empty,
-readability-convert-member-functions-to-static,
-readability-function-cognitive-complexity,
-readability-function-size,
diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml
index 902417375a8..10cbf319d3d 100644
--- a/.github/workflows/CI-unixish.yml
+++ b/.github/workflows/CI-unixish.yml
@@ -85,6 +85,8 @@ jobs:
sudo apt-get update
sudo apt-get install libxml2-utils qtbase5-dev qttools5-dev libqt5charts5-dev qtchooser
+ # TODO: move latest compiler to separate step
+ # TODO: bail out on warnings with latest GCC
- name: Set up GCC
uses: egor-tensin/setup-gcc@v1
if: matrix.os == 'ubuntu-22.04'
@@ -93,9 +95,9 @@ jobs:
platform: x64
- name: Select compiler
+ if: matrix.os == 'ubuntu-22.04'
run: |
echo "CXX=g++-13" >> $GITHUB_ENV
- if: matrix.os == 'ubuntu-22.04'
# coreutils contains "nproc"
- name: Install missing software on macos
@@ -460,9 +462,11 @@ jobs:
- name: Self check
run: |
- selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ -DCHECK_INTERNAL -DHAVE_RULES --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings --check-level=exhaustive"
+ selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ -D__GNUC__ -DCHECK_INTERNAL -DHAVE_RULES --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings --check-level=exhaustive"
ec=0
+ # TODO: add --check-config
+
# early exit
if [ $ec -eq 1 ]; then
exit $ec
diff --git a/.github/workflows/CI-windows.yml b/.github/workflows/CI-windows.yml
index 4da98719ded..98df86f8558 100644
--- a/.github/workflows/CI-windows.yml
+++ b/.github/workflows/CI-windows.yml
@@ -13,6 +13,8 @@ defaults:
run:
shell: cmd
+# TODO: choose/add a step to bail out on compiler warnings (maybe even the release build)
+
jobs:
build_qt:
diff --git a/.github/workflows/asan.yml b/.github/workflows/asan.yml
index fe7c5a95a77..c29ecde8a4a 100644
--- a/.github/workflows/asan.yml
+++ b/.github/workflows/asan.yml
@@ -82,7 +82,7 @@ jobs:
- name: Self check
if: false
run: |
- selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ -DCHECK_INTERNAL -DHAVE_RULES --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings"
+ selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ -D__GNUC__ -DCHECK_INTERNAL -DHAVE_RULES --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings"
ec=0
./cmake.output/bin/cppcheck $selfcheck_options --addon=naming.json cli lib || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 -DQT_CHARTS_LIB --library=qt --addon=naming.json -Icmake.output/gui -Igui gui/*.cpp cmake.output/gui/*.cpp || ec=1
diff --git a/.github/workflows/tsan.yml b/.github/workflows/tsan.yml
index 6114817c194..876e1976141 100644
--- a/.github/workflows/tsan.yml
+++ b/.github/workflows/tsan.yml
@@ -82,7 +82,7 @@ jobs:
- name: Self check
if: false
run: |
- selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ -DCHECK_INTERNAL -DHAVE_RULES --error-exitcode=0 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings"
+ selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ -D__GNUC__ -DCHECK_INTERNAL -DHAVE_RULES --error-exitcode=0 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings"
ec=0
./cmake.output/bin/cppcheck $selfcheck_options --addon=naming.json -DCHECK_INTERNAL cli lib || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 -DQT_CHARTS_LIB --library=qt --addon=naming.json -Icmake.output/gui -Igui gui/*.cpp cmake.output/gui/*.cpp || ec=1
diff --git a/.github/workflows/ubsan.yml b/.github/workflows/ubsan.yml
index 3076801002e..2a422710b74 100644
--- a/.github/workflows/ubsan.yml
+++ b/.github/workflows/ubsan.yml
@@ -78,7 +78,7 @@ jobs:
# TODO: only fail the step on sanitizer issues - since we use processes it will only fail the underlying process which will result in an cppcheckError
- name: Self check
run: |
- selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ -DCHECK_INTERNAL -DHAVE_RULES --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings"
+ selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ -D__GNUC__ -DCHECK_INTERNAL -DHAVE_RULES --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings"
ec=0
./cmake.output/bin/cppcheck $selfcheck_options --addon=naming.json cli lib || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 -DQT_CHARTS_LIB --library=qt --addon=naming.json -Icmake.output/gui -Igui gui/*.cpp cmake.output/gui/*.cpp || ec=1
diff --git a/Makefile b/Makefile
index 946755da0cb..d1256debd8e 100644
--- a/Makefile
+++ b/Makefile
@@ -455,7 +455,7 @@ validateRules:
###### Build
-$(libcppdir)/analyzerinfo.o: lib/analyzerinfo.cpp externals/tinyxml2/tinyxml2.h lib/analyzerinfo.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/path.h lib/platform.h lib/suppressions.h lib/utils.h
+$(libcppdir)/analyzerinfo.o: lib/analyzerinfo.cpp externals/tinyxml2/tinyxml2.h lib/analyzerinfo.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/path.h lib/platform.h lib/utils.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/analyzerinfo.cpp
$(libcppdir)/astutils.o: lib/astutils.cpp lib/astutils.h lib/check.h lib/checkclass.h lib/config.h lib/errortypes.h lib/importproject.h lib/infer.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vfvalue.h
@@ -545,7 +545,7 @@ $(libcppdir)/clangimport.o: lib/clangimport.cpp lib/clangimport.h lib/config.h l
$(libcppdir)/color.o: lib/color.cpp lib/color.h lib/config.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/color.cpp
-$(libcppdir)/cppcheck.o: lib/cppcheck.cpp externals/picojson/picojson.h externals/simplecpp/simplecpp.h externals/tinyxml2/tinyxml2.h lib/analyzerinfo.h lib/check.h lib/checkunusedfunctions.h lib/clangimport.h lib/color.h lib/config.h lib/cppcheck.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/importproject.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/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/version.h lib/vfvalue.h
+$(libcppdir)/cppcheck.o: lib/cppcheck.cpp externals/picojson/picojson.h externals/simplecpp/simplecpp.h externals/tinyxml2/tinyxml2.h lib/analyzerinfo.h lib/check.h lib/checkunusedfunctions.h lib/clangimport.h lib/color.h lib/config.h lib/cppcheck.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/json.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/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/version.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/cppcheck.cpp
$(libcppdir)/ctu.o: lib/ctu.cpp externals/tinyxml2/tinyxml2.h lib/astutils.h lib/check.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
@@ -563,7 +563,7 @@ $(libcppdir)/forwardanalyzer.o: lib/forwardanalyzer.cpp lib/analyzer.h lib/astut
$(libcppdir)/fwdanalysis.o: lib/fwdanalysis.cpp lib/astutils.h lib/config.h lib/errortypes.h lib/fwdanalysis.h lib/library.h lib/mathlib.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/fwdanalysis.cpp
-$(libcppdir)/importproject.o: lib/importproject.cpp externals/picojson/picojson.h externals/simplecpp/simplecpp.h externals/tinyxml2/tinyxml2.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.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
+$(libcppdir)/importproject.o: lib/importproject.cpp externals/picojson/picojson.h externals/simplecpp/simplecpp.h externals/tinyxml2/tinyxml2.h lib/config.h lib/errortypes.h lib/importproject.h lib/json.h lib/library.h lib/mathlib.h lib/path.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
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/importproject.cpp
$(libcppdir)/infer.o: lib/infer.cpp lib/calculate.h lib/config.h lib/errortypes.h lib/infer.h lib/mathlib.h lib/valueptr.h lib/vfvalue.h
@@ -599,7 +599,7 @@ $(libcppdir)/programmemory.o: lib/programmemory.cpp lib/astutils.h lib/calculate
$(libcppdir)/reverseanalyzer.o: lib/reverseanalyzer.cpp lib/analyzer.h lib/astutils.h lib/config.h lib/errortypes.h lib/forwardanalyzer.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/reverseanalyzer.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/valueptr.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/reverseanalyzer.cpp
-$(libcppdir)/settings.o: lib/settings.cpp externals/picojson/picojson.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/summaries.h lib/suppressions.h lib/timer.h lib/utils.h lib/vfvalue.h
+$(libcppdir)/settings.o: lib/settings.cpp externals/picojson/picojson.h lib/config.h lib/errortypes.h lib/importproject.h lib/json.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/summaries.h lib/suppressions.h lib/timer.h lib/utils.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/settings.cpp
$(libcppdir)/summaries.o: lib/summaries.cpp lib/analyzerinfo.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/summaries.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
@@ -629,7 +629,7 @@ $(libcppdir)/tokenlist.o: lib/tokenlist.cpp externals/simplecpp/simplecpp.h lib/
$(libcppdir)/utils.o: lib/utils.cpp lib/config.h lib/utils.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/utils.cpp
-$(libcppdir)/valueflow.o: lib/valueflow.cpp lib/analyzer.h lib/astutils.h lib/calculate.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/forwardanalyzer.h lib/importproject.h lib/infer.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/programmemory.h lib/reverseanalyzer.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vfvalue.h
+$(libcppdir)/valueflow.o: lib/valueflow.cpp lib/analyzer.h lib/astutils.h lib/calculate.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/forwardanalyzer.h lib/importproject.h lib/infer.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/programmemory.h lib/reverseanalyzer.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/valueflow.cpp
$(libcppdir)/vfvalue.o: lib/vfvalue.cpp lib/config.h lib/errortypes.h lib/mathlib.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/vfvalue.h
@@ -641,10 +641,10 @@ cli/cmdlineparser.o: cli/cmdlineparser.cpp cli/cmdlineparser.h cli/cppcheckexecu
cli/cppcheckexecutor.o: cli/cppcheckexecutor.cpp cli/cmdlineparser.h cli/cppcheckexecutor.h cli/cppcheckexecutorseh.h cli/cppcheckexecutorsig.h cli/executor.h cli/filelister.h cli/processexecutor.h cli/singleexecutor.h cli/threadexecutor.h lib/analyzerinfo.h lib/check.h lib/checkunusedfunctions.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/pathmatch.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/cppcheckexecutor.cpp
-cli/cppcheckexecutorseh.o: cli/cppcheckexecutorseh.cpp cli/cppcheckexecutor.h cli/cppcheckexecutorseh.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/suppressions.h lib/utils.h
+cli/cppcheckexecutorseh.o: cli/cppcheckexecutorseh.cpp cli/cppcheckexecutor.h cli/cppcheckexecutorseh.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/utils.h
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/cppcheckexecutorseh.cpp
-cli/cppcheckexecutorsig.o: cli/cppcheckexecutorsig.cpp cli/cppcheckexecutor.h cli/cppcheckexecutorsig.h cli/stacktrace.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/suppressions.h
+cli/cppcheckexecutorsig.o: cli/cppcheckexecutorsig.cpp cli/cppcheckexecutor.h cli/cppcheckexecutorsig.h cli/stacktrace.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/cppcheckexecutorsig.cpp
cli/executor.o: cli/executor.cpp cli/executor.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/utils.h
@@ -653,7 +653,7 @@ cli/executor.o: cli/executor.cpp cli/executor.h lib/color.h lib/config.h lib/err
cli/filelister.o: cli/filelister.cpp cli/filelister.h lib/config.h lib/path.h lib/pathmatch.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/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/suppressions.h
+cli/main.o: cli/main.cpp cli/cppcheckexecutor.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/main.cpp
cli/processexecutor.o: cli/processexecutor.cpp cli/cppcheckexecutor.h cli/executor.h cli/processexecutor.h lib/analyzerinfo.h lib/check.h lib/color.h lib/config.h lib/cppcheck.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/utils.h
@@ -716,7 +716,7 @@ test/testclangimport.o: test/testclangimport.cpp lib/check.h lib/clangimport.h l
test/testclass.o: test/testclass.cpp externals/simplecpp/simplecpp.h lib/check.h lib/checkclass.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/preprocessor.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.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/testclass.cpp
-test/testcmdlineparser.o: test/testcmdlineparser.cpp cli/cmdlineparser.h cli/cppcheckexecutor.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/suppressions.h lib/timer.h lib/utils.h test/fixture.h test/redirect.h
+test/testcmdlineparser.o: test/testcmdlineparser.cpp cli/cmdlineparser.h cli/cppcheckexecutor.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/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h test/redirect.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testcmdlineparser.cpp
test/testcolor.o: test/testcolor.cpp 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/suppressions.h lib/utils.h test/fixture.h
diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c
index 2fd30c7e707..d4e7f39ad6c 100644
--- a/addons/test/misra/misra-test.c
+++ b/addons/test/misra/misra-test.c
@@ -645,11 +645,11 @@ static void misra_10_1_ternary(void)
a = ui16 << ui16; // 10.6
a = ui16 << (get_bool(42) ? ui16 : ui16);
- a = ui16 << (get_bool(42) ? ui16 : (get_bool(34) ? ui16 : ui16)); // 10.4
- a = ui16 << (get_bool(42) ? (get_bool(34) ? ui16 : ui16) : ui16); // 10.4
- a = ui16 << (get_bool(42) ? i16 : (get_bool(34) ? ui16 : ui16)); // 10.1
+ a = ui16 << (get_bool(42) ? ui16 : (get_bool(34) ? ui16 : ui16));
+ a = ui16 << (get_bool(42) ? (get_bool(34) ? ui16 : ui16) : ui16);
+ a = ui16 << (get_bool(42) ? i16 : (get_bool(34) ? ui16 : ui16)); // 10.1 10.4
a = ui16 << (get_bool(42) ? (get_bool(34) ? ui16 : i16) : ui16); // 10.1 10.4
- a = ui16 << (get_bool(42) ? (get_bool(34) ? ui16 : ui16) : i16); // 10.1
+ a = ui16 << (get_bool(42) ? (get_bool(34) ? ui16 : ui16) : i16); // 10.1 10.4
a = ui16 << (get_bool(42) ? (get_bool(34) ? ui16 : ui8) : ui8); // 10.4
a = ui16 << (get_bool(42) ? (get_bool(34) ? i16 : ui8) : ui8); // 10.1 10.4
a = (get_bool(42) ? (get_bool(34) ? ui16 : ui8) : ui8) << ui16; // 10.4
@@ -1171,7 +1171,7 @@ static void misra_14_2_fn1(bool b) {
g += 2;
i2 ^= 2; // 14.2
if (i2 == 2) {
- g += g_arr[i2];
+ g += g_arr[i2]; // cppcheck-suppress legacyUninitvar
}
misra_14_2_init_value(&i2); // TODO: Fix false negative in function call
}
diff --git a/cfg/windows.cfg b/cfg/windows.cfg
index 105ee469b56..53dc335e463 100644
--- a/cfg/windows.cfg
+++ b/cfg/windows.cfg
@@ -2176,7 +2176,7 @@
false
-
+
@@ -3432,7 +3432,7 @@ HFONT CreateFont(
-
+
@@ -3487,7 +3487,7 @@ HFONT CreateFont(
-
+
@@ -3501,7 +3501,7 @@ HFONT CreateFont(
false
-
+
@@ -4726,7 +4726,7 @@ HFONT CreateFont(
-
+
@@ -4806,7 +4806,7 @@ HFONT CreateFont(
true
-
+
@@ -4821,7 +4821,7 @@ HFONT CreateFont(
false
-
+
@@ -5646,7 +5646,7 @@ HFONT CreateFont(
-
+
@@ -6791,7 +6791,7 @@ HFONT CreateFont(
-
+
diff --git a/clang-tidy.md b/clang-tidy.md
index 2311d2d3a97..b85031ac25c 100644
--- a/clang-tidy.md
+++ b/clang-tidy.md
@@ -63,7 +63,6 @@ This does not appear to be useful as it is reported on very common code.
It was decided not to apply these.
-`modernize-use-equals-default`
`modernize-loop-convert`
These might change the behavior of code which might not be intended (need to file an upstream issue)
@@ -129,7 +128,6 @@ Also reports a false positive about templates which deduce the array length: htt
We run this separately via `clang-include-cleaner` in the `iwyu.yml` workflow as the findings of the include checkers still need to be reviewed manually before applying them.
-`readability-container-size-empty`
`bugprone-branch-clone`
`readability-const-return-type`
`modernize-return-braced-init-list`
diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp
index 92b5c6a0a78..e2a575533cc 100644
--- a/cli/cmdlineparser.cpp
+++ b/cli/cmdlineparser.cpp
@@ -507,10 +507,17 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
printError("argument to '-j' is not valid - " + err + ".");
return false;
}
- if (tmp > 10000) {
- // This limit is here just to catch typos. If someone has
- // need for more jobs, this value should be increased.
- printError("argument for '-j' is allowed to be 10000 at max.");
+ if (tmp == 0) {
+ // TODO: implement get CPU logical core count and use that.
+ // Usually, -j 0 would mean "use all available cores," but
+ // if we get a 0, we just stall and don't do any work.
+ printError("argument for '-j' must be greater than 0.");
+ return false;
+ }
+ if (tmp > 1024) {
+ // Almost nobody has 1024 logical cores, but somebody out
+ // there does.
+ printError("argument for '-j' is allowed to be 1024 at max.");
return false;
}
mSettings.jobs = tmp;
@@ -892,7 +899,6 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
}
}
- // TODO: deprecate "--template "
// Output formatter
else if (std::strcmp(argv[i], "--template") == 0 ||
std::strncmp(argv[i], "--template=", 11) == 0) {
@@ -900,6 +906,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
if (argv[i][10] == '=')
mSettings.templateFormat = argv[i] + 11;
else if ((i+1) < argc && argv[i+1][0] != '-') {
+ printMessage("'--template ' is deprecated and will be removed in 2.13 - please use '--template=' instead");
++i;
mSettings.templateFormat = argv[i];
} else {
@@ -928,13 +935,13 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
}
}
- // TODO: deprecate "--template-location "
else if (std::strcmp(argv[i], "--template-location") == 0 ||
std::strncmp(argv[i], "--template-location=", 20) == 0) {
// "--template-location format"
if (argv[i][19] == '=')
mSettings.templateLocation = argv[i] + 20;
else if ((i+1) < argc && argv[i+1][0] != '-') {
+ printMessage("'--template-location ' is deprecated and will be removed in 2.13 - please use '--template-location=' instead");
++i;
mSettings.templateLocation = argv[i];
} else {
diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp
index eabf0582022..540619939e2 100644
--- a/cli/cppcheckexecutor.cpp
+++ b/cli/cppcheckexecutor.cpp
@@ -261,11 +261,11 @@ bool CppCheckExecutor::reportSuppressions(const Settings &settings, bool unusedF
bool err = false;
if (settings.useSingleJob()) {
for (std::map::const_iterator i = files.cbegin(); i != files.cend(); ++i) {
- err |= errorLogger.reportUnmatchedSuppressions(
- settings.nomsg.getUnmatchedLocalSuppressions(i->first, unusedFunctionCheckEnabled));
+ err |= Suppressions::reportUnmatchedSuppressions(
+ settings.nomsg.getUnmatchedLocalSuppressions(i->first, unusedFunctionCheckEnabled), errorLogger);
}
}
- err |= errorLogger.reportUnmatchedSuppressions(settings.nomsg.getUnmatchedGlobalSuppressions(unusedFunctionCheckEnabled));
+ err |= Suppressions::reportUnmatchedSuppressions(settings.nomsg.getUnmatchedGlobalSuppressions(unusedFunctionCheckEnabled), errorLogger);
return err;
}
diff --git a/cli/cppcheckexecutor.h b/cli/cppcheckexecutor.h
index 23e845e0e6f..e5577396d75 100644
--- a/cli/cppcheckexecutor.h
+++ b/cli/cppcheckexecutor.h
@@ -43,6 +43,8 @@ class Settings;
*/
class CppCheckExecutor : public ErrorLogger {
public:
+ friend class TestSuppressions;
+
/**
* Constructor
*/
@@ -101,8 +103,6 @@ class CppCheckExecutor : public ErrorLogger {
*/
static bool executeCommand(std::string exe, std::vector args, std::string redirect, std::string &output_);
- static bool reportSuppressions(const Settings &settings, bool unusedFunctionCheckEnabled, const std::map &files, ErrorLogger& errorLogger);
-
protected:
/**
@@ -124,6 +124,8 @@ class CppCheckExecutor : public ErrorLogger {
private:
+ static bool reportSuppressions(const Settings &settings, bool unusedFunctionCheckEnabled, const std::map &files, ErrorLogger& errorLogger);
+
/**
* Wrapper around check_internal
* - installs optional platform dependent signal handling
diff --git a/cli/cppcheckexecutorsig.cpp b/cli/cppcheckexecutorsig.cpp
index e8d447682eb..c5347d8e5ac 100644
--- a/cli/cppcheckexecutorsig.cpp
+++ b/cli/cppcheckexecutorsig.cpp
@@ -101,6 +101,7 @@ static const Signalmap_t listofsignals = {
* but when ending up here something went terribly wrong anyway.
* And all which is left is just printing some information and terminate.
*/
+// cppcheck-suppress constParameterCallback
static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
{
int type = -1;
@@ -119,7 +120,9 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
const Signalmap_t::const_iterator it=listofsignals.find(signo);
const char * const signame = (it==listofsignals.end()) ? "unknown" : it->second.c_str();
+#ifdef USE_UNIX_BACKTRACE_SUPPORT
bool lowMem=false; // was low-memory condition detected? Be careful then! Avoid allocating much more memory then.
+#endif
bool unexpectedSignal=true; // unexpected indicates program failure
bool terminate=true; // exit process/thread
const bool isAddressOnStack = IsAddressOnStack(info->si_addr);
@@ -135,7 +138,9 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
" - out of memory or assertion?\n",
#endif
output);
+#ifdef USE_UNIX_BACKTRACE_SUPPORT
lowMem=true; // educated guess
+#endif
break;
case SIGBUS:
fputs("Internal error: cppcheck received signal ", output);
@@ -296,7 +301,7 @@ int check_wrapper_sig(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(Cpp
{
// determine stack vs. heap
char stackVariable;
- char *heapVariable=(char*)malloc(1);
+ char *heapVariable=static_cast(malloc(1));
bStackBelowHeap = &stackVariable < heapVariable;
free(heapVariable);
diff --git a/cli/executor.cpp b/cli/executor.cpp
index 489d9f8951b..c7955d71704 100644
--- a/cli/executor.cpp
+++ b/cli/executor.cpp
@@ -31,9 +31,6 @@ Executor::Executor(const std::map &files, const Settin
: mFiles(files), mSettings(settings), mSuppressions(suppressions), mErrorLogger(errorLogger)
{}
-Executor::~Executor()
-{}
-
bool Executor::hasToLog(const ErrorMessage &msg)
{
if (!mSuppressions.isSuppressed(msg))
diff --git a/cli/executor.h b/cli/executor.h
index 1b7db25e71e..8c67c6cfedd 100644
--- a/cli/executor.h
+++ b/cli/executor.h
@@ -40,7 +40,7 @@ class Suppressions;
class Executor {
public:
Executor(const std::map &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
- virtual ~Executor();
+ virtual ~Executor() = default;
Executor(const Executor &) = delete;
void operator=(const Executor &) = delete;
diff --git a/cli/filelister.cpp b/cli/filelister.cpp
index c83b3756967..59a6028653b 100644
--- a/cli/filelister.cpp
+++ b/cli/filelister.cpp
@@ -192,29 +192,10 @@ static std::string addFiles2(std::map &files,
if (!dir)
return "";
- dirent * dir_result;
- // make sure we reserve enough space for the readdir_r() buffer;
- // according to POSIX:
- // The storage pointed to by entry shall be large enough for a
- // dirent with an array of char d_name members containing at
- // least {NAME_MAX}+1 elements.
- // on some platforms, d_name is not a static sized-array but
- // a pointer to space usually reserved right after the dirent
- // struct; the union here allows to reserve the space and to
- // provide a pointer to the right type that can be passed where
- // needed without casts
- union {
- dirent entry;
- char buf[sizeof(*dir_result) + (sizeof(dir_result->d_name) > 1 ? 0 : NAME_MAX + 1)];
- } dir_result_buffer;
- // TODO: suppress instead?
- (void)dir_result_buffer.buf; // do not trigger cppcheck itself on the "unused buf"
- std::string new_path;
- new_path.reserve(path.length() + 1 + sizeof(dir_result->d_name));// prealloc some memory to avoid constant new/deletes in loop
- new_path += path;
+ std::string new_path = path;
new_path += '/';
- while ((SUPPRESS_DEPRECATED_WARNING(readdir_r(dir, &dir_result_buffer.entry, &dir_result)) == 0) && (dir_result != nullptr)) {
+ while (const struct dirent* dir_result = readdir(dir)) {
if ((std::strcmp(dir_result->d_name, ".") == 0) ||
(std::strcmp(dir_result->d_name, "..") == 0))
continue;
diff --git a/cli/processexecutor.cpp b/cli/processexecutor.cpp
index be9c61d1548..566e503eb32 100644
--- a/cli/processexecutor.cpp
+++ b/cli/processexecutor.cpp
@@ -67,9 +67,6 @@ ProcessExecutor::ProcessExecutor(const std::map &files
assert(mSettings.jobs > 1);
}
-ProcessExecutor::~ProcessExecutor()
-{}
-
class PipeWriter : public ErrorLogger {
public:
enum PipeSignal {REPORT_OUT='1',REPORT_ERROR='2', CHILD_END='5'};
@@ -90,32 +87,35 @@ class PipeWriter : public ErrorLogger {
private:
// TODO: how to log file name in error?
- void writeToPipe(PipeSignal type, const std::string &data) const
+ void writeToPipeInternal(PipeSignal type, const void* data, std::size_t to_write) const
{
- unsigned int len = static_cast(data.length() + 1);
- char *out = new char[len + 1 + sizeof(len)];
- out[0] = static_cast(type);
- std::memcpy(&(out[1]), &len, sizeof(len));
- std::memcpy(&(out[1+sizeof(len)]), data.c_str(), len);
-
- std::size_t bytes_to_write = len + 1 + sizeof(len);
- ssize_t bytes_written = write(mWpipe, out, len + 1 + sizeof(len));
+ const ssize_t bytes_written = write(mWpipe, data, to_write);
if (bytes_written <= 0) {
const int err = errno;
- delete[] out;
- out = nullptr;
- std::cerr << "#### ThreadExecutor::writeToPipe() error for type " << type << ": " << std::strerror(err) << std::endl;
+ std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": " << std::strerror(err) << std::endl;
std::exit(EXIT_FAILURE);
}
// TODO: write until everything is written
- if (bytes_written != bytes_to_write) {
- delete[] out;
- out = nullptr;
- std::cerr << "#### ThreadExecutor::writeToPipe() error for type " << type << ": insufficient data written (expected: " << bytes_to_write << " / got: " << bytes_written << ")" << std::endl;
+ if (bytes_written != to_write) {
+ std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": insufficient data written (expected: " << to_write << " / got: " << bytes_written << ")" << std::endl;
std::exit(EXIT_FAILURE);
}
+ }
+
+ void writeToPipe(PipeSignal type, const std::string &data) const
+ {
+ {
+ const char t = static_cast(type);
+ writeToPipeInternal(type, &t, 1);
+ }
+
+ const unsigned int len = static_cast(data.length() + 1);
+ {
+ static constexpr std::size_t l_size = sizeof(unsigned int);
+ writeToPipeInternal(type, &len, l_size);
+ }
- delete[] out;
+ writeToPipeInternal(type, data.c_str(), len);
}
const int mWpipe;
@@ -164,8 +164,8 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
// Don't rely on incoming data being null-terminated.
// Allocate +1 element and null-terminate the buffer.
- char *buf = new char[len + 1];
- char *data_start = buf;
+ std::string buf(len + 1, '\0');
+ char *data_start = &buf[0];
bytes_to_read = len;
do {
bytes_read = read(rpipe, data_start, bytes_to_read);
@@ -177,13 +177,14 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
bytes_to_read -= bytes_read;
data_start += bytes_read;
} while (bytes_to_read != 0);
- buf[len] = 0;
+ buf[len] = '\0';
bool res = true;
if (type == PipeWriter::REPORT_OUT) {
// the first character is the color
const Color c = static_cast(buf[0]);
- mErrorLogger.reportOut(buf + 1, c);
+ // TODO: avoid string copy
+ mErrorLogger.reportOut(buf.substr(1), c);
} else if (type == PipeWriter::REPORT_ERROR) {
ErrorMessage msg;
try {
@@ -200,7 +201,6 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
res = false;
}
- delete[] buf;
return res;
}
diff --git a/cli/processexecutor.h b/cli/processexecutor.h
index 4b51d596acc..580c344cfae 100644
--- a/cli/processexecutor.h
+++ b/cli/processexecutor.h
@@ -40,7 +40,6 @@ class ProcessExecutor : public Executor {
public:
ProcessExecutor(const std::map &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
ProcessExecutor(const ProcessExecutor &) = delete;
- ~ProcessExecutor() override;
void operator=(const ProcessExecutor &) = delete;
unsigned int check() override;
diff --git a/cli/singleexecutor.cpp b/cli/singleexecutor.cpp
index c3fea886b24..c52c984d996 100644
--- a/cli/singleexecutor.cpp
+++ b/cli/singleexecutor.cpp
@@ -37,9 +37,6 @@ SingleExecutor::SingleExecutor(CppCheck &cppcheck, const std::map &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
SingleExecutor(const SingleExecutor &) = delete;
- ~SingleExecutor() override;
void operator=(const SingleExecutor &) = delete;
unsigned int check() override;
diff --git a/cli/threadexecutor.cpp b/cli/threadexecutor.cpp
index a6a9e671bd0..96f35ac4015 100644
--- a/cli/threadexecutor.cpp
+++ b/cli/threadexecutor.cpp
@@ -46,9 +46,6 @@ ThreadExecutor::ThreadExecutor(const std::map &files,
assert(mSettings.jobs > 1);
}
-ThreadExecutor::~ThreadExecutor()
-{}
-
class SyncLogForwarder : public ErrorLogger
{
public:
diff --git a/cli/threadexecutor.h b/cli/threadexecutor.h
index 62ad8e0a860..8ebae323b5b 100644
--- a/cli/threadexecutor.h
+++ b/cli/threadexecutor.h
@@ -40,7 +40,6 @@ class ThreadExecutor : public Executor {
public:
ThreadExecutor(const std::map &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
ThreadExecutor(const ThreadExecutor &) = delete;
- ~ThreadExecutor() override;
void operator=(const ThreadExecutor &) = delete;
unsigned int check() override;
diff --git a/cmake/compileroptions.cmake b/cmake/compileroptions.cmake
index e7d0a3bf787..4c5ad9af858 100644
--- a/cmake/compileroptions.cmake
+++ b/cmake/compileroptions.cmake
@@ -95,8 +95,6 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options_safe(-Wno-suggest-override) # TODO: enable when warnings are fixed in in tinyxml2
add_compile_options_safe(-Wno-suggest-destructor-override) # TODO: enable when warnings are fixed in in tinyxml2
add_compile_options_safe(-Wno-extra-semi-stmt) # TODO: enable when warnings are fixed in in tinyxml2
- add_compile_options_safe(-Wno-implicitly-unsigned-literal)
- add_compile_options_safe(-Wno-tautological-type-limit-compare)
add_compile_options(-Wno-disabled-macro-expansion)
add_compile_options_safe(-Wno-bitwise-instead-of-logical)
diff --git a/createrelease b/createrelease
index c99964be13d..0a98f850266 100755
--- a/createrelease
+++ b/createrelease
@@ -11,7 +11,7 @@
#
# self check, fix critical issues:
# make clean && make CXXFLAGS=-O2 MATCHCOMPILER=yes -j4
-# ./cppcheck -D__CPPCHECK__ -DCHECK_INTERNAL -DHAVE_RULES --std=c++11 --library=cppcheck-lib --library=qt --enable=style --inconclusive --inline-suppr --suppress=bitwiseOnBoolean --suppress=shadowFunction --suppress=useStlAlgorithm --suppress=*:externals/picojson.h --suppress=functionConst --suppress=functionStatic --xml cli gui/*.cpp lib 2> selfcheck.xml
+# ./cppcheck -D__CPPCHECK__ -D__GNUC__ -DCHECK_INTERNAL -DHAVE_RULES --std=c++11 --library=cppcheck-lib --library=qt --enable=style --inconclusive --inline-suppr --suppress=bitwiseOnBoolean --suppress=shadowFunction --suppress=useStlAlgorithm --suppress=*:externals/picojson.h --suppress=functionConst --suppress=functionStatic --xml cli gui/*.cpp lib 2> selfcheck.xml
#
# Update translations
# lupdate gui.pro
@@ -82,7 +82,7 @@
# 2. scp -i ../.ssh/osuosl_id_rsa tools/donate-cpu-server.py danielmarjamaki@cppcheck1.osuosl.org:/var/daca@home/
#
# self check, fix stylistic issues:
-# ./cppcheck -D__CPPCHECK__ -DCHECK_INTERNAL -DHAVE_RULES --library=cppcheck-lib --enable=style --inconclusive --inline-suppr --suppress=bitwiseOnBoolean --suppress=shadowFunction --suppress=useStlAlgorithm --suppress=*:externals/picojson.h cli gui/*.cpp lib
+# ./cppcheck -D__CPPCHECK__ -D__GNUC__ -DCHECK_INTERNAL -DHAVE_RULES --library=cppcheck-lib --enable=style --inconclusive --inline-suppr --suppress=bitwiseOnBoolean --suppress=shadowFunction --suppress=useStlAlgorithm --suppress=*:externals/picojson.h cli gui/*.cpp lib
#
# Set debug version (see 803eea912c9512c810a7e78d58bb927d89a6daa1)
diff --git a/gui/application.h b/gui/application.h
index ee624bf07cd..a5bbc31a323 100644
--- a/gui/application.h
+++ b/gui/application.h
@@ -42,7 +42,7 @@
*/
class Application {
public:
- Application() {}
+ Application() = default;
Application(QString name, QString path, QString params);
/**
diff --git a/gui/checkthread.cpp b/gui/checkthread.cpp
index b45f30c6eb0..0a8fbf34631 100644
--- a/gui/checkthread.cpp
+++ b/gui/checkthread.cpp
@@ -86,14 +86,7 @@ static bool executeCommand(std::string exe, std::vector args, std::
CheckThread::CheckThread(ThreadResult &result) :
mResult(result),
mCppcheck(result, true, executeCommand)
-{
- //ctor
-}
-
-CheckThread::~CheckThread()
-{
- //dtor
-}
+{}
void CheckThread::check(const Settings &settings)
{
diff --git a/gui/checkthread.h b/gui/checkthread.h
index d74ec2514a9..65b6f782061 100644
--- a/gui/checkthread.h
+++ b/gui/checkthread.h
@@ -46,7 +46,6 @@ class CheckThread : public QThread {
Q_OBJECT
public:
explicit CheckThread(ThreadResult &result);
- ~CheckThread() override;
/**
* @brief Set settings for cppcheck
diff --git a/gui/codeeditstylecontrols.h b/gui/codeeditstylecontrols.h
index 7e87c7b5fc0..7285598ad73 100644
--- a/gui/codeeditstylecontrols.h
+++ b/gui/codeeditstylecontrols.h
@@ -35,7 +35,6 @@ class SelectColorButton : public QPushButton {
Q_OBJECT
public:
explicit SelectColorButton(QWidget* parent);
- ~SelectColorButton() override {}
void setColor(const QColor& color);
const QColor& getColor();
@@ -57,7 +56,6 @@ class SelectFontWeightCombo : public QComboBox {
Q_OBJECT
public:
explicit SelectFontWeightCombo(QWidget* parent);
- ~SelectFontWeightCombo() override {}
void setWeight(const QFont::Weight& weight);
const QFont::Weight& getWeight();
diff --git a/gui/codeeditstyledialog.h b/gui/codeeditstyledialog.h
index 9ef42907be4..c4aeffc99e8 100644
--- a/gui/codeeditstyledialog.h
+++ b/gui/codeeditstyledialog.h
@@ -42,7 +42,6 @@ class StyleEditDialog : public QDialog {
public:
explicit StyleEditDialog(const CodeEditorStyle& newStyle,
QWidget *parent = nullptr);
- ~StyleEditDialog() override {}
CodeEditorStyle getStyle();
diff --git a/gui/cppchecklibrarydata.cpp b/gui/cppchecklibrarydata.cpp
index 2e7761a6534..83fe76622f6 100644
--- a/gui/cppchecklibrarydata.cpp
+++ b/gui/cppchecklibrarydata.cpp
@@ -35,9 +35,6 @@
const unsigned int CppcheckLibraryData::Function::Arg::ANY = ~0U;
const unsigned int CppcheckLibraryData::Function::Arg::VARIADIC = ~1U;
-CppcheckLibraryData::CppcheckLibraryData()
-{}
-
static std::string unhandledElement(const QXmlStreamReader &xmlReader)
{
throw std::runtime_error(QObject::tr("line %1: Unhandled element %2").arg(xmlReader.lineNumber()).arg(xmlReader.name().toString()).toStdString());
diff --git a/gui/cppchecklibrarydata.h b/gui/cppchecklibrarydata.h
index 252d66920ba..07fc2a81107 100644
--- a/gui/cppchecklibrarydata.h
+++ b/gui/cppchecklibrarydata.h
@@ -30,7 +30,7 @@ class QIODevice;
class CppcheckLibraryData {
public:
- CppcheckLibraryData();
+ CppcheckLibraryData() = default;
struct Container {
QString id;
diff --git a/gui/csvreport.cpp b/gui/csvreport.cpp
index 36da50bbde5..740651cf06f 100644
--- a/gui/csvreport.cpp
+++ b/gui/csvreport.cpp
@@ -30,9 +30,6 @@ CsvReport::CsvReport(const QString &filename) :
Report(filename)
{}
-CsvReport::~CsvReport()
-{}
-
bool CsvReport::create()
{
if (Report::create()) {
diff --git a/gui/csvreport.h b/gui/csvreport.h
index a2efdd93b0a..cfd918fe082 100644
--- a/gui/csvreport.h
+++ b/gui/csvreport.h
@@ -39,7 +39,6 @@ class ErrorItem;
class CsvReport : public Report {
public:
explicit CsvReport(const QString &filename);
- ~CsvReport() override;
/**
* @brief Create the report (file).
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp
index 2840c48330d..fd5dc6dfff0 100644
--- a/gui/mainwindow.cpp
+++ b/gui/mainwindow.cpp
@@ -697,7 +697,7 @@ void MainWindow::analyzeFiles()
QStringList selected = selectFilesToAnalyze(QFileDialog::ExistingFiles);
- const QString file0 = (selected.size() ? selected[0].toLower() : QString());
+ const QString file0 = (!selected.empty() ? selected[0].toLower() : QString());
if (file0.endsWith(".sln")
|| file0.endsWith(".vcxproj")
|| file0.endsWith(compile_commands_json)
diff --git a/gui/printablereport.cpp b/gui/printablereport.cpp
index 9bcfff55c34..d9272632f45 100644
--- a/gui/printablereport.cpp
+++ b/gui/printablereport.cpp
@@ -27,9 +27,6 @@ PrintableReport::PrintableReport() :
Report(QString())
{}
-PrintableReport::~PrintableReport()
-{}
-
bool PrintableReport::create()
{
return true;
diff --git a/gui/printablereport.h b/gui/printablereport.h
index 29fa008bf61..693356a961d 100644
--- a/gui/printablereport.h
+++ b/gui/printablereport.h
@@ -36,7 +36,6 @@ class ErrorItem;
class PrintableReport : public Report {
public:
PrintableReport();
- ~PrintableReport() override;
/**
* @brief Create the report (file).
diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp
index 61f995e6bf4..946437f9602 100644
--- a/gui/resultstree.cpp
+++ b/gui/resultstree.cpp
@@ -91,9 +91,6 @@ ResultsTree::ResultsTree(QWidget * parent) :
connect(this, &ResultsTree::doubleClicked, this, &ResultsTree::quickStartApplication);
}
-ResultsTree::~ResultsTree()
-{}
-
void ResultsTree::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
@@ -815,7 +812,15 @@ void ResultsTree::startApplication(QStandardItem *target, int application)
const QString cmdLine = QString("%1 %2").arg(program).arg(params);
// this is reported as deprecated in Qt 5.15.2 but no longer in Qt 6
- const bool success = SUPPRESS_DEPRECATED_WARNING(QProcess::startDetached(cmdLine));
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
+ SUPPRESS_WARNING_CLANG_PUSH("-Wdeprecated")
+ SUPPRESS_WARNING_GCC_PUSH("-Wdeprecated-declarations")
+#endif
+ const bool success = QProcess::startDetached(cmdLine);
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
+ SUPPRESS_WARNING_GCC_POP
+ SUPPRESS_WARNING_CLANG_POP
+#endif
if (!success) {
QString text = tr("Could not start %1\n\nPlease check the application path and parameters are correct.").arg(program);
diff --git a/gui/resultstree.h b/gui/resultstree.h
index 5828c0e383b..8a8a79642b4 100644
--- a/gui/resultstree.h
+++ b/gui/resultstree.h
@@ -53,7 +53,7 @@ class ResultsTree : public QTreeView {
Q_OBJECT
public:
explicit ResultsTree(QWidget * parent = nullptr);
- ~ResultsTree() override;
+
void initialize(QSettings *settings, ApplicationList *list, ThreadHandler *checkThreadHandler);
/**
diff --git a/gui/test/cppchecklibrarydata/testcppchecklibrarydata.cpp b/gui/test/cppchecklibrarydata/testcppchecklibrarydata.cpp
index aadb090d1e7..015e8a60dec 100644
--- a/gui/test/cppchecklibrarydata/testcppchecklibrarydata.cpp
+++ b/gui/test/cppchecklibrarydata/testcppchecklibrarydata.cpp
@@ -620,7 +620,7 @@ void TestCppcheckLibraryData::validateAllCfg()
{
const QDir dir(QString(SRCDIR) + "/../../../cfg/");
const QStringList files = dir.entryList(QStringList() << "*.cfg",QDir::Files);
- QVERIFY(files.size() != 0);
+ QVERIFY(!files.empty());
bool error = false;
for (const QString& f : files) {
loadCfgFile(dir.absolutePath() + "/" + f, fileLibraryData, result);
diff --git a/gui/test/projectfile/testprojectfile.cpp b/gui/test/projectfile/testprojectfile.cpp
index cbd98dc86ca..65531aa0fa3 100644
--- a/gui/test/projectfile/testprojectfile.cpp
+++ b/gui/test/projectfile/testprojectfile.cpp
@@ -40,8 +40,8 @@ const char Settings::SafeChecks::XmlExternalFunctions[] = "external-functions";
const char Settings::SafeChecks::XmlInternalFunctions[] = "internal-functions";
const char Settings::SafeChecks::XmlExternalVariables[] = "external-variables";
Settings::Settings() : maxCtuDepth(10) {}
-cppcheck::Platform::Platform() {}
-ImportProject::ImportProject() {}
+cppcheck::Platform::Platform() = default;
+ImportProject::ImportProject() = default;
bool ImportProject::sourceFileExists(const std::string & /*file*/) {
return true;
}
diff --git a/gui/threadresult.cpp b/gui/threadresult.cpp
index 5e1aed89b78..52d683414a8 100644
--- a/gui/threadresult.cpp
+++ b/gui/threadresult.cpp
@@ -28,11 +28,6 @@
#include
#include
-ThreadResult::~ThreadResult()
-{
- //dtor
-}
-
void ThreadResult::reportOut(const std::string &outmsg, Color /*c*/)
{
emit log(QString::fromStdString(outmsg));
diff --git a/gui/threadresult.h b/gui/threadresult.h
index f08bb945230..4e32a1cbef2 100644
--- a/gui/threadresult.h
+++ b/gui/threadresult.h
@@ -46,7 +46,6 @@ class ThreadResult : public QObject, public ErrorLogger {
Q_OBJECT
public:
ThreadResult() = default;
- ~ThreadResult() override;
/**
* @brief Get next unprocessed file
diff --git a/gui/translationhandler.cpp b/gui/translationhandler.cpp
index 6b14b6241fb..2e17148fd2a 100644
--- a/gui/translationhandler.cpp
+++ b/gui/translationhandler.cpp
@@ -62,9 +62,6 @@ TranslationHandler::TranslationHandler(QObject *parent) :
addTranslation("Swedish", "cppcheck_sv");
}
-TranslationHandler::~TranslationHandler()
-{}
-
bool TranslationHandler::setLanguage(const QString &code)
{
bool failure = false;
diff --git a/gui/translationhandler.h b/gui/translationhandler.h
index e9ff8722058..cd298d6ebaf 100644
--- a/gui/translationhandler.h
+++ b/gui/translationhandler.h
@@ -63,7 +63,6 @@ class TranslationHandler : QObject {
Q_OBJECT
public:
explicit TranslationHandler(QObject *parent = nullptr);
- ~TranslationHandler() override;
/**
* @brief Get a list of available translations.
diff --git a/gui/txtreport.cpp b/gui/txtreport.cpp
index 1be3944341c..caa3833ef8d 100644
--- a/gui/txtreport.cpp
+++ b/gui/txtreport.cpp
@@ -29,9 +29,6 @@ TxtReport::TxtReport(const QString &filename) :
Report(filename)
{}
-TxtReport::~TxtReport()
-{}
-
bool TxtReport::create()
{
if (Report::create()) {
diff --git a/gui/txtreport.h b/gui/txtreport.h
index 02395cc4484..d3e74f93d7c 100644
--- a/gui/txtreport.h
+++ b/gui/txtreport.h
@@ -40,7 +40,6 @@ class TxtReport : public Report {
public:
explicit TxtReport(const QString &filename);
- ~TxtReport() override;
/**
* @brief Create the report (file).
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 741e6c2adfc..e4332578a95 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -56,16 +56,3 @@ endif()
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
target_precompile_headers(cppcheck-core PRIVATE precompiled.h)
endif()
-
-if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
- # -Wfloat-equal is generated by picojson.h
- if (NOT USE_MATCHCOMPILER_OPT STREQUAL "Off")
- set_source_files_properties(mc_cppcheck.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
- set_source_files_properties(mc_importproject.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
- set_source_files_properties(mc_settings.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
- else()
- set_source_files_properties(cppcheck.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
- set_source_files_properties(importproject.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
- set_source_files_properties(settings.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
- endif()
-endif()
diff --git a/lib/analyzer.h b/lib/analyzer.h
index 3c65e0e68de..3ceab711b32 100644
--- a/lib/analyzer.h
+++ b/lib/analyzer.h
@@ -184,7 +184,7 @@ struct Analyzer {
virtual bool invalid() const {
return false;
}
- virtual ~Analyzer() {}
+ virtual ~Analyzer() = default;
Analyzer(const Analyzer&) = default;
protected:
Analyzer() = default;
diff --git a/lib/astutils.cpp b/lib/astutils.cpp
index b1dc9900af7..78252680e11 100644
--- a/lib/astutils.cpp
+++ b/lib/astutils.cpp
@@ -259,6 +259,18 @@ bool astIsContainerOwned(const Token* tok) {
return astIsContainer(tok) && !astIsContainerView(tok);
}
+bool astIsContainerString(const Token* tok)
+{
+ if (!tok)
+ return false;
+ if (!tok->valueType())
+ return false;
+ const Library::Container* container = tok->valueType()->container;
+ if (!container)
+ return false;
+ return container->stdStringLike;
+}
+
static const Token* getContainerFunction(const Token* tok)
{
if (!tok || !tok->valueType() || !tok->valueType()->container)
@@ -329,7 +341,7 @@ static bool match(const Token *tok, const std::string &rhs)
{
if (tok->str() == rhs)
return true;
- if (!tok->varId() && tok->hasKnownIntValue() && MathLib::toString(tok->values().front().intvalue) == rhs)
+ if (!tok->varId() && tok->hasKnownIntValue() && std::to_string(tok->values().front().intvalue) == rhs)
return true;
return false;
}
@@ -726,7 +738,7 @@ std::vector getParentValueTypes(const Token* tok, const Settings* set
const ValueType* vtCont = contTok->valueType();
if (!vtCont->containerTypeToken)
return {};
- ValueType vtParent = ValueType::parseDecl(vtCont->containerTypeToken, *settings, true); // TODO: set isCpp
+ ValueType vtParent = ValueType::parseDecl(vtCont->containerTypeToken, *settings);
return {std::move(vtParent)};
}
if (Token::Match(tok->astParent(), "return|(|{|%assign%") && parent) {
@@ -888,9 +900,16 @@ bool extractForLoopValues(const Token *forToken,
if (!initExpr || !initExpr->isBinaryOp() || initExpr->str() != "=" || !Token::Match(initExpr->astOperand1(), "%var%"))
return false;
std::vector minInitValue = getMinValue(ValueFlow::makeIntegralInferModel(), initExpr->astOperand2()->values());
+ if (minInitValue.empty()) {
+ const ValueFlow::Value* v = initExpr->astOperand2()->getMinValue(true);
+ if (v)
+ minInitValue.push_back(v->intvalue);
+ }
+ if (minInitValue.empty())
+ return false;
varid = initExpr->astOperand1()->varId();
knownInitValue = initExpr->astOperand2()->hasKnownIntValue();
- initValue = minInitValue.empty() ? 0 : minInitValue.front();
+ initValue = minInitValue.front();
partialCond = Token::Match(condExpr, "%oror%|&&");
visitAstNodes(condExpr, [varid, &condExpr](const Token *tok) {
if (Token::Match(tok, "%oror%|&&"))
@@ -1445,6 +1464,19 @@ static bool astIsBoolLike(const Token* tok)
return astIsBool(tok) || isUsedAsBool(tok);
}
+bool isBooleanFuncArg(const Token* tok) {
+ if (tok->variable() && tok->variable()->valueType() && tok->variable()->valueType()->type == ValueType::BOOL) // skip trivial case: bool passed as bool
+ return false;
+ int argn{};
+ const Token* ftok = getTokenArgumentFunction(tok, argn);
+ if (!ftok)
+ return false;
+ std::vector argvars = getArgumentVars(ftok, argn);
+ if (argvars.size() != 1)
+ return false;
+ return !argvars[0]->isReference() && argvars[0]->valueType() && argvars[0]->valueType()->type == ValueType::BOOL;
+}
+
bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2, const Library& library, bool pure, bool followVar, ErrorPath* errors)
{
if (tok1 == nullptr && tok2 == nullptr)
@@ -3129,30 +3161,33 @@ static ExprUsage getFunctionUsage(const Token* tok, int indirect, const Settings
return ExprUsage::Inconclusive;
}
-ExprUsage getExprUsage(const Token* tok, int indirect, const Settings* settings)
+ExprUsage getExprUsage(const Token* tok, int indirect, const Settings* settings, bool cpp)
{
- if (indirect > 0 && tok->astParent()) {
- if (Token::Match(tok->astParent(), "%assign%") && astIsRHS(tok))
+ const Token* const parent = tok->astParent();
+ if (indirect > 0 && parent) {
+ if (Token::Match(parent, "%assign%") && astIsRHS(tok))
return ExprUsage::NotUsed;
- if (tok->astParent()->isConstOp())
+ if (parent->isConstOp())
return ExprUsage::NotUsed;
- if (tok->astParent()->isCast())
+ if (parent->isCast())
return ExprUsage::NotUsed;
- if (Token::simpleMatch(tok->astParent(), ":") && Token::simpleMatch(tok->astParent()->astParent(), "?"))
- return getExprUsage(tok->astParent()->astParent(), indirect, settings);
+ if (Token::simpleMatch(parent, ":") && Token::simpleMatch(parent->astParent(), "?"))
+ return getExprUsage(parent->astParent(), indirect, settings, cpp);
}
if (indirect == 0) {
- if (Token::Match(tok->astParent(), "%cop%|%assign%|++|--") && !Token::Match(tok->astParent(), "=|>>") &&
- !tok->astParent()->isUnaryOp("&"))
+ if (Token::Match(parent, "%cop%|%assign%|++|--") && parent->str() != "=" &&
+ !parent->isUnaryOp("&") &&
+ !(astIsRHS(tok) && isLikelyStreamRead(cpp, parent)))
return ExprUsage::Used;
- if (Token::simpleMatch(tok->astParent(), "=") && astIsRHS(tok)) {
- if (tok->astParent()->astOperand1() && tok->astParent()->astOperand1()->variable() && tok->astParent()->astOperand1()->variable()->isReference())
+ if (Token::simpleMatch(parent, "=") && astIsRHS(tok)) {
+ const Token* const lhs = parent->astOperand1();
+ if (lhs && lhs->variable() && lhs->variable()->isReference() && lhs == lhs->variable()->nameToken())
return ExprUsage::NotUsed;
return ExprUsage::Used;
}
// Function call or index
- if (((Token::simpleMatch(tok->astParent(), "(") && !tok->astParent()->isCast()) || (Token::simpleMatch(tok->astParent(), "[") && tok->valueType())) &&
- (astIsLHS(tok) || Token::simpleMatch(tok->astParent(), "( )")))
+ if (((Token::simpleMatch(parent, "(") && !parent->isCast()) || (Token::simpleMatch(parent, "[") && tok->valueType())) &&
+ (astIsLHS(tok) || Token::simpleMatch(parent, "( )")))
return ExprUsage::Used;
}
return getFunctionUsage(tok, indirect, settings);
diff --git a/lib/astutils.h b/lib/astutils.h
index 04143bc7f57..0ef08ece023 100644
--- a/lib/astutils.h
+++ b/lib/astutils.h
@@ -149,6 +149,7 @@ bool astIsContainer(const Token *tok);
bool astIsContainerView(const Token* tok);
bool astIsContainerOwned(const Token* tok);
+bool astIsContainerString(const Token* tok);
Library::Container::Action astContainerAction(const Token* tok, const Token** ftok = nullptr);
Library::Container::Yield astContainerYield(const Token* tok, const Token** ftok = nullptr);
@@ -251,10 +252,15 @@ bool isStructuredBindingVariable(const Variable* var);
const Token* isInLoopCondition(const Token* tok);
/**
- * Is token used a boolean, that is to say cast to a bool, or used as a condition in a if/while/for
+ * Is token used as boolean, that is to say cast to a bool, or used as a condition in a if/while/for
*/
CPPCHECKLIB bool isUsedAsBool(const Token * const tok);
+/**
+ * Is token passed to a function taking a bool argument
+ */
+CPPCHECKLIB bool isBooleanFuncArg(const Token* tok);
+
/**
* Are two conditions opposite
* @param isNot do you want to know if cond1 is !cond2 or if cond1 and cond2 are non-overlapping. true: cond1==!cond2 false: cond1==true => cond2==false
@@ -409,7 +415,7 @@ bool isConstVarExpression(const Token* tok, std::function sk
enum class ExprUsage { None, NotUsed, PassedByReference, Used, Inconclusive };
-ExprUsage getExprUsage(const Token* tok, int indirect, const Settings* settings);
+ExprUsage getExprUsage(const Token* tok, int indirect, const Settings* settings, bool cpp);
const Variable *getLHSVariable(const Token *tok);
diff --git a/lib/check.cpp b/lib/check.cpp
index bc67e683dfc..de7b3892c10 100644
--- a/lib/check.cpp
+++ b/lib/check.cpp
@@ -55,7 +55,7 @@ Check::Check(const std::string &aname)
instances().insert(it, this);
}
-void Check::reportError(const ErrorMessage &errmsg)
+void Check::writeToErrorList(const ErrorMessage &errmsg)
{
std::cout << errmsg.toXML() << std::endl;
}
@@ -67,7 +67,7 @@ void Check::reportError(const std::list &callstack, Severity::Sev
if (mErrorLogger)
mErrorLogger->reportErr(errmsg);
else
- reportError(errmsg);
+ writeToErrorList(errmsg);
}
void Check::reportError(const ErrorPath &errorPath, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty)
@@ -76,7 +76,7 @@ void Check::reportError(const ErrorPath &errorPath, Severity::SeverityType sever
if (mErrorLogger)
mErrorLogger->reportErr(errmsg);
else
- reportError(errmsg);
+ writeToErrorList(errmsg);
}
bool Check::wrongData(const Token *tok, const char *str)
diff --git a/lib/check.h b/lib/check.h
index 39e34781505..5421c64a71c 100644
--- a/lib/check.h
+++ b/lib/check.h
@@ -77,7 +77,7 @@ class CPPCHECKLIB Check {
static std::list &instances();
/** run checks, the token list is not simplified */
- virtual void runChecks(const Tokenizer *, const Settings *, ErrorLogger *) = 0;
+ virtual void runChecks(const Tokenizer &, ErrorLogger *) = 0;
/** get error messages */
virtual void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const = 0;
@@ -91,17 +91,17 @@ class CPPCHECKLIB Check {
virtual std::string classInfo() const = 0;
/**
- * Write given error to errorlogger or to out stream in xml format.
+ * Write given error to stdout in xml format.
* This is for for printout out the error list with --errorlist
* @param errmsg Error message to write
*/
- static void reportError(const ErrorMessage &errmsg);
+ static void writeToErrorList(const ErrorMessage &errmsg);
/** Base class used for whole-program analysis */
class CPPCHECKLIB FileInfo {
public:
- FileInfo() {}
- virtual ~FileInfo() {}
+ FileInfo() = default;
+ virtual ~FileInfo() = default;
virtual std::string toString() const {
return std::string();
}
diff --git a/lib/check64bit.h b/lib/check64bit.h
index 67f10c42e38..e79acbd8567 100644
--- a/lib/check64bit.h
+++ b/lib/check64bit.h
@@ -24,13 +24,13 @@
#include "check.h"
#include "config.h"
+#include "tokenize.h"
#include
class ErrorLogger;
class Settings;
class Token;
-class Tokenizer;
/// @addtogroup Checks
@@ -50,8 +50,8 @@ class CPPCHECKLIB Check64BitPortability : public Check {
: Check(myName(), tokenizer, settings, errorLogger) {}
/** @brief Run checks against the normal token list */
- void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
- Check64BitPortability check64BitPortability(tokenizer, settings, errorLogger);
+ void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
+ Check64BitPortability check64BitPortability(&tokenizer, tokenizer.getSettings(), errorLogger);
check64BitPortability.pointerassignment();
}
diff --git a/lib/checkassert.h b/lib/checkassert.h
index 78ce0905c4c..e2455a921ce 100644
--- a/lib/checkassert.h
+++ b/lib/checkassert.h
@@ -24,6 +24,7 @@
#include "check.h"
#include "config.h"
+#include "tokenize.h"
#include
@@ -31,7 +32,6 @@ class ErrorLogger;
class Scope;
class Settings;
class Token;
-class Tokenizer;
/// @addtogroup Checks
/// @{
@@ -48,8 +48,8 @@ class CPPCHECKLIB CheckAssert : public Check {
: Check(myName(), tokenizer, settings, errorLogger) {}
/** run checks, the token list is not simplified */
- void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
- CheckAssert checkAssert(tokenizer, settings, errorLogger);
+ void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
+ CheckAssert checkAssert(&tokenizer, tokenizer.getSettings(), errorLogger);
checkAssert.assertWithSideEffects();
}
diff --git a/lib/checkautovariables.h b/lib/checkautovariables.h
index ea70beba372..b02a0d0a6c3 100644
--- a/lib/checkautovariables.h
+++ b/lib/checkautovariables.h
@@ -25,13 +25,13 @@
#include "check.h"
#include "config.h"
#include "errortypes.h"
+#include "tokenize.h"
#include
#include
class Settings;
class Token;
-class Tokenizer;
class ErrorLogger;
class Variable;
@@ -54,8 +54,8 @@ class CPPCHECKLIB CheckAutoVariables : public Check {
: Check(myName(), tokenizer, settings, errorLogger) {}
/** @brief Run checks against the normal token list */
- void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
- CheckAutoVariables checkAutoVariables(tokenizer, settings, errorLogger);
+ void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
+ CheckAutoVariables checkAutoVariables(&tokenizer, tokenizer.getSettings(), errorLogger);
checkAutoVariables.assignFunctionArg();
checkAutoVariables.checkVarLifetime();
checkAutoVariables.autoVariables();
diff --git a/lib/checkbool.h b/lib/checkbool.h
index d6213a58dbb..94d1714a97e 100644
--- a/lib/checkbool.h
+++ b/lib/checkbool.h
@@ -24,13 +24,13 @@
#include "check.h"
#include "config.h"
+#include "tokenize.h"
#include
class ErrorLogger;
class Settings;
class Token;
-class Tokenizer;
/// @addtogroup Checks
/// @{
@@ -48,8 +48,8 @@ class CPPCHECKLIB CheckBool : public Check {
: Check(myName(), tokenizer, settings, errorLogger) {}
/** @brief Run checks against the normal token list */
- void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
- CheckBool checkBool(tokenizer, settings, errorLogger);
+ void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
+ CheckBool checkBool(&tokenizer, tokenizer.getSettings(), errorLogger);
// Checks
checkBool.checkComparisonOfBoolExpressionWithInt();
diff --git a/lib/checkboost.h b/lib/checkboost.h
index a232ad22cf1..1ea25b28501 100644
--- a/lib/checkboost.h
+++ b/lib/checkboost.h
@@ -47,11 +47,11 @@ class CPPCHECKLIB CheckBoost : public Check {
: Check(myName(), tokenizer, settings, errorLogger) {}
/** @brief Run checks against the normal token list */
- void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
- if (!tokenizer->isCPP())
+ void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
+ if (!tokenizer.isCPP())
return;
- CheckBoost checkBoost(tokenizer, settings, errorLogger);
+ CheckBoost checkBoost(&tokenizer, tokenizer.getSettings(), errorLogger);
checkBoost.checkBoostForeachModification();
}
diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp
index d0dbe95dacf..cf5ec86fd71 100644
--- a/lib/checkbufferoverrun.cpp
+++ b/lib/checkbufferoverrun.cpp
@@ -119,7 +119,7 @@ static int getMinFormatStringOutputLength(const std::vector ¶m
i_d_x_f_found = true;
parameterLength = 1;
if (inputArgNr < parameters.size() && parameters[inputArgNr]->hasKnownIntValue())
- parameterLength = MathLib::toString(parameters[inputArgNr]->getKnownIntValue()).length();
+ parameterLength = std::to_string(parameters[inputArgNr]->getKnownIntValue()).length();
handleNextParameter = true;
break;
@@ -362,7 +362,7 @@ void CheckBufferOverrun::arrayIndex()
static std::string stringifyIndexes(const std::string& array, const std::vector& indexValues)
{
if (indexValues.size() == 1)
- return MathLib::toString(indexValues[0].intvalue);
+ return std::to_string(indexValues[0].intvalue);
std::ostringstream ret;
ret << array;
@@ -383,7 +383,7 @@ static std::string arrayIndexMessage(const Token* tok,
const Token* condition)
{
auto add_dim = [](const std::string &s, const Dimension &dim) {
- return s + "[" + MathLib::toString(dim.num) + "]";
+ return s + "[" + std::to_string(dim.num) + "]";
};
const std::string array = std::accumulate(dimensions.cbegin(), dimensions.cend(), tok->astOperand1()->expressionString(), add_dim);
@@ -528,7 +528,7 @@ void CheckBufferOverrun::pointerArithmeticError(const Token *tok, const Token *i
std::string errmsg;
if (indexValue->condition)
- errmsg = "Undefined behaviour, when '" + indexToken->expressionString() + "' is " + MathLib::toString(indexValue->intvalue) + " the pointer arithmetic '" + tok->expressionString() + "' is out of bounds.";
+ errmsg = "Undefined behaviour, when '" + indexToken->expressionString() + "' is " + std::to_string(indexValue->intvalue) + " the pointer arithmetic '" + tok->expressionString() + "' is out of bounds.";
else
errmsg = "Undefined behaviour, pointer arithmetic '" + tok->expressionString() + "' is out of bounds.";
@@ -992,13 +992,13 @@ bool CheckBufferOverrun::analyseWholeProgram1(const std::map 0)
- errmsg = "Array index out of bounds; '" + unsafeUsage.myArgumentName + "' buffer size is " + MathLib::toString(functionCall->callArgValue) + " and it is accessed at offset " + MathLib::toString(unsafeUsage.value) + ".";
+ errmsg = "Array index out of bounds; '" + unsafeUsage.myArgumentName + "' buffer size is " + std::to_string(functionCall->callArgValue) + " and it is accessed at offset " + std::to_string(unsafeUsage.value) + ".";
else
- errmsg = "Array index out of bounds; buffer '" + unsafeUsage.myArgumentName + "' is accessed at offset " + MathLib::toString(unsafeUsage.value) + ".";
+ errmsg = "Array index out of bounds; buffer '" + unsafeUsage.myArgumentName + "' is accessed at offset " + std::to_string(unsafeUsage.value) + ".";
cwe = (unsafeUsage.value > 0) ? CWE_BUFFER_OVERRUN : CWE_BUFFER_UNDERRUN;
} else {
errorId = "ctuPointerArith";
- errmsg = "Pointer arithmetic overflow; '" + unsafeUsage.myArgumentName + "' buffer size is " + MathLib::toString(functionCall->callArgValue);
+ errmsg = "Pointer arithmetic overflow; '" + unsafeUsage.myArgumentName + "' buffer size is " + std::to_string(functionCall->callArgValue);
cwe = CWE_POINTER_ARITHMETIC_OVERFLOW;
}
diff --git a/lib/checkbufferoverrun.h b/lib/checkbufferoverrun.h
index d402330dd56..16e3a7532da 100644
--- a/lib/checkbufferoverrun.h
+++ b/lib/checkbufferoverrun.h
@@ -28,6 +28,7 @@
#include "errortypes.h"
#include "mathlib.h"
#include "symboldatabase.h"
+#include "tokenize.h"
#include "vfvalue.h"
#include
@@ -42,7 +43,6 @@ namespace tinyxml2 {
class ErrorLogger;
class Settings;
class Token;
-class Tokenizer;
/// @addtogroup Checks
/// @{
@@ -66,8 +66,8 @@ class CPPCHECKLIB CheckBufferOverrun : public Check {
CheckBufferOverrun(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {}
- void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
- CheckBufferOverrun checkBufferOverrun(tokenizer, settings, errorLogger);
+ void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
+ CheckBufferOverrun checkBufferOverrun(&tokenizer, tokenizer.getSettings(), errorLogger);
checkBufferOverrun.arrayIndex();
checkBufferOverrun.pointerArithmetic();
checkBufferOverrun.bufferOverflow();
diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp
index 662a6707619..29a94f024bd 100644
--- a/lib/checkclass.cpp
+++ b/lib/checkclass.cpp
@@ -2845,7 +2845,7 @@ void CheckClass::virtualFunctionCallInConstructorError(
}
reportError(errorPath, Severity::style, "virtualCallInConstructor",
- "Virtual function '" + funcname + "' is called from " + scopeFunctionTypeName + " '" + constructorName + "' at line " + MathLib::toString(lineNumber) + ". Dynamic binding is not used.", CWE(0U), Certainty::normal);
+ "Virtual function '" + funcname + "' is called from " + scopeFunctionTypeName + " '" + constructorName + "' at line " + std::to_string(lineNumber) + ". Dynamic binding is not used.", CWE(0U), Certainty::normal);
}
void CheckClass::pureVirtualFunctionCallInConstructorError(
@@ -3228,7 +3228,7 @@ void CheckClass::checkThisUseAfterFree()
for (const Variable &var : classScope->varlist) {
// Find possible "self pointer".. pointer/smartpointer member variable of "self" type.
if (var.valueType() && var.valueType()->smartPointerType != classScope->definedType && var.valueType()->typeScope != classScope) {
- const ValueType valueType = ValueType::parseDecl(var.typeStartToken(), *mSettings, true); // this is only called for C++
+ const ValueType valueType = ValueType::parseDecl(var.typeStartToken(), *mSettings);
if (valueType.smartPointerType != classScope->definedType)
continue;
}
diff --git a/lib/checkclass.h b/lib/checkclass.h
index ffb94d3a247..3134ebf152f 100644
--- a/lib/checkclass.h
+++ b/lib/checkclass.h
@@ -59,11 +59,11 @@ class CPPCHECKLIB CheckClass : public Check {
CheckClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger);
/** @brief Run checks on the normal token list */
- void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
- if (tokenizer->isC())
+ void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
+ if (tokenizer.isC())
return;
- CheckClass checkClass(tokenizer, settings, errorLogger);
+ CheckClass checkClass(&tokenizer, tokenizer.getSettings(), errorLogger);
// can't be a simplified check .. the 'sizeof' is used.
checkClass.checkMemset();
diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp
index be1283232ea..8219d04b1ec 100644
--- a/lib/checkcondition.cpp
+++ b/lib/checkcondition.cpp
@@ -1039,7 +1039,7 @@ static bool parseComparison(const Token *comp, bool ¬1, std::string &op, std:
return false;
op = invertOperatorForOperandSwap(comp->str());
if (op1->enumerator() && op1->enumerator()->value_known)
- value = MathLib::toString(op1->enumerator()->value);
+ value = std::to_string(op1->enumerator()->value);
else
value = op1->str();
expr = op2;
@@ -1048,7 +1048,7 @@ static bool parseComparison(const Token *comp, bool ¬1, std::string &op, std:
return false;
op = comp->str();
if (op2->enumerator() && op2->enumerator()->value_known)
- value = MathLib::toString(op2->enumerator()->value);
+ value = std::to_string(op2->enumerator()->value);
else
value = op2->str();
expr = op1;
@@ -1466,7 +1466,7 @@ void CheckCondition::alwaysTrueFalse()
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
if (Token::simpleMatch(tok, "<") && tok->link()) // don't write false positives when templates are used
continue;
- if (!tok->hasKnownIntValue())
+ if (!tok->hasKnownBoolValue())
continue;
if (Token::Match(tok->previous(), "%name% (") && tok->previous()->function()) {
const Function* f = tok->previous()->function();
@@ -1490,6 +1490,8 @@ void CheckCondition::alwaysTrueFalse()
else if (parent->str() == ";" && parent->astParent() && parent->astParent()->astParent() &&
Token::simpleMatch(parent->astParent()->astParent()->previous(), "for ("))
condition = parent->astParent()->astParent()->previous();
+ else if (isBooleanFuncArg(tok))
+ condition = tok;
else
continue;
}
@@ -1580,14 +1582,17 @@ void CheckCondition::alwaysTrueFalse()
if (hasSizeof)
continue;
- alwaysTrueFalseError(tok, condition, &tok->values().front());
+ auto it = std::find_if(tok->values().begin(), tok->values().end(), [](const ValueFlow::Value& v) {
+ return v.isIntValue();
+ });
+ alwaysTrueFalseError(tok, condition, &*it);
}
}
}
void CheckCondition::alwaysTrueFalseError(const Token* tok, const Token* condition, const ValueFlow::Value* value)
{
- const bool alwaysTrue = value && (value->intvalue != 0);
+ const bool alwaysTrue = value && (value->intvalue != 0 || value->isImpossible());
const std::string expr = tok ? tok->expressionString() : std::string("x");
const std::string conditionStr = (Token::simpleMatch(condition, "return") ? "Return value" : "Condition");
const std::string errmsg = conditionStr + " '" + expr + "' is always " + (alwaysTrue ? "true" : "false");
diff --git a/lib/checkcondition.h b/lib/checkcondition.h
index 57e09c50b49..948dd7be217 100644
--- a/lib/checkcondition.h
+++ b/lib/checkcondition.h
@@ -26,13 +26,13 @@
#include "config.h"
#include "mathlib.h"
#include "errortypes.h"
+#include "tokenize.h"
#include
#include
class Settings;
class Token;
-class Tokenizer;
class ErrorLogger;
class ValueType;
@@ -56,8 +56,8 @@ class CPPCHECKLIB CheckCondition : public Check {
CheckCondition(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {}
- void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
- CheckCondition checkCondition(tokenizer, settings, errorLogger);
+ void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
+ CheckCondition checkCondition(&tokenizer, tokenizer.getSettings(), errorLogger);
checkCondition.multiCondition();
checkCondition.clarifyCondition(); // not simplified because ifAssign
checkCondition.multiCondition2();
diff --git a/lib/checkexceptionsafety.h b/lib/checkexceptionsafety.h
index 6f90b881c7a..f70573c4bc2 100644
--- a/lib/checkexceptionsafety.h
+++ b/lib/checkexceptionsafety.h
@@ -53,11 +53,11 @@ class CPPCHECKLIB CheckExceptionSafety : public Check {
CheckExceptionSafety(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) {}
- void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
- if (tokenizer->isC())
+ void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
+ if (tokenizer.isC())
return;
- CheckExceptionSafety checkExceptionSafety(tokenizer, settings, errorLogger);
+ CheckExceptionSafety checkExceptionSafety(&tokenizer, tokenizer.getSettings(), errorLogger);
checkExceptionSafety.destructors();
checkExceptionSafety.deallocThrow();
checkExceptionSafety.checkRethrowCopy();
diff --git a/lib/checkfunctions.h b/lib/checkfunctions.h
index bff40c2eb00..05502a870f3 100644
--- a/lib/checkfunctions.h
+++ b/lib/checkfunctions.h
@@ -27,13 +27,13 @@
#include "errortypes.h"
#include "library.h"
#include "settings.h"
+#include "tokenize.h"
#include