Skip to content

Commit d8b44df

Browse files
authored
fixed/suppressed several compiler warnings (#5327)
1 parent 84a9b3a commit d8b44df

18 files changed

Lines changed: 96 additions & 42 deletions

.github/workflows/CI-unixish.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ jobs:
8585
sudo apt-get update
8686
sudo apt-get install libxml2-utils qtbase5-dev qttools5-dev libqt5charts5-dev qtchooser
8787
88+
# TODO: move latest compiler to separate step
89+
# TODO: bail out on warnings with latest GCC
8890
- name: Set up GCC
8991
uses: egor-tensin/setup-gcc@v1
9092
if: matrix.os == 'ubuntu-22.04'
@@ -93,9 +95,9 @@ jobs:
9395
platform: x64
9496

9597
- name: Select compiler
98+
if: matrix.os == 'ubuntu-22.04'
9699
run: |
97100
echo "CXX=g++-13" >> $GITHUB_ENV
98-
if: matrix.os == 'ubuntu-22.04'
99101
100102
# coreutils contains "nproc"
101103
- name: Install missing software on macos

.github/workflows/CI-windows.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ defaults:
1313
run:
1414
shell: cmd
1515

16+
# TODO: choose/add a step to bail out on compiler warnings (maybe even the release build)
17+
1618
jobs:
1719

1820
build_qt:

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ $(libcppdir)/clangimport.o: lib/clangimport.cpp lib/clangimport.h lib/config.h l
545545
$(libcppdir)/color.o: lib/color.cpp lib/color.h lib/config.h
546546
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/color.cpp
547547

548-
$(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
548+
$(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
549549
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/cppcheck.cpp
550550

551551
$(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
563563
$(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
564564
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/fwdanalysis.cpp
565565

566-
$(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
566+
$(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
567567
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/importproject.cpp
568568

569569
$(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
599599
$(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
600600
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/reverseanalyzer.cpp
601601

602-
$(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
602+
$(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
603603
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/settings.cpp
604604

605605
$(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

cmake/compileroptions.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
9595
add_compile_options_safe(-Wno-suggest-override) # TODO: enable when warnings are fixed in in tinyxml2
9696
add_compile_options_safe(-Wno-suggest-destructor-override) # TODO: enable when warnings are fixed in in tinyxml2
9797
add_compile_options_safe(-Wno-extra-semi-stmt) # TODO: enable when warnings are fixed in in tinyxml2
98-
add_compile_options_safe(-Wno-implicitly-unsigned-literal)
99-
add_compile_options_safe(-Wno-tautological-type-limit-compare)
10098
add_compile_options(-Wno-disabled-macro-expansion)
10199
add_compile_options_safe(-Wno-bitwise-instead-of-logical)
102100

gui/resultstree.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,15 @@ void ResultsTree::startApplication(QStandardItem *target, int application)
812812
const QString cmdLine = QString("%1 %2").arg(program).arg(params);
813813

814814
// this is reported as deprecated in Qt 5.15.2 but no longer in Qt 6
815-
const bool success = SUPPRESS_DEPRECATED_WARNING(QProcess::startDetached(cmdLine));
815+
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
816+
SUPPRESS_WARNING_CLANG_PUSH("-Wdeprecated")
817+
SUPPRESS_WARNING_GCC_PUSH("-Wdeprecated-declarations")
818+
#endif
819+
const bool success = QProcess::startDetached(cmdLine);
820+
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
821+
SUPPRESS_WARNING_GCC_POP
822+
SUPPRESS_WARNING_CLANG_POP
823+
#endif
816824
if (!success) {
817825
QString text = tr("Could not start %1\n\nPlease check the application path and parameters are correct.").arg(program);
818826

lib/CMakeLists.txt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,3 @@ endif()
5656
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
5757
target_precompile_headers(cppcheck-core PRIVATE precompiled.h)
5858
endif()
59-
60-
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
61-
# -Wfloat-equal is generated by picojson.h
62-
if (NOT USE_MATCHCOMPILER_OPT STREQUAL "Off")
63-
set_source_files_properties(mc_cppcheck.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
64-
set_source_files_properties(mc_importproject.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
65-
set_source_files_properties(mc_settings.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
66-
else()
67-
set_source_files_properties(cppcheck.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
68-
set_source_files_properties(importproject.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
69-
set_source_files_properties(settings.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
70-
endif()
71-
endif()

lib/config.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,26 @@ static const std::string emptyString;
133133
#define STRINGISIZE(...) #__VA_ARGS__
134134

135135
#ifdef __clang__
136-
#define SUPPRESS_WARNING(warning, ...)_Pragma("clang diagnostic push") _Pragma(STRINGISIZE(clang diagnostic ignored warning)) __VA_ARGS__ _Pragma("clang diagnostic pop")
137-
#define SUPPRESS_DEPRECATED_WARNING(...) SUPPRESS_WARNING("-Wdeprecated", __VA_ARGS__)
138-
#define SUPPRESS_FLOAT_EQUAL_WARNING(...) SUPPRESS_WARNING("-Wfloat-equal", __VA_ARGS__)
136+
#define SUPPRESS_WARNING_PUSH(warning) _Pragma("clang diagnostic push") _Pragma(STRINGISIZE(clang diagnostic ignored warning))
137+
#define SUPPRESS_WARNING_POP _Pragma("clang diagnostic pop")
138+
#define SUPPRESS_WARNING_GCC_PUSH(warning)
139+
#define SUPPRESS_WARNING_GCC_POP
140+
#define SUPPRESS_WARNING_CLANG_PUSH(warning) SUPPRESS_WARNING_PUSH(warning)
141+
#define SUPPRESS_WARNING_CLANG_POP SUPPRESS_WARNING_POP
142+
#elif defined(__GNUC__)
143+
#define SUPPRESS_WARNING_PUSH(warning) _Pragma("GCC diagnostic push") _Pragma(STRINGISIZE(GCC diagnostic ignored warning))
144+
#define SUPPRESS_WARNING_POP _Pragma("GCC diagnostic pop")
145+
#define SUPPRESS_WARNING_GCC_PUSH(warning) SUPPRESS_WARNING_PUSH(warning)
146+
#define SUPPRESS_WARNING_GCC_POP SUPPRESS_WARNING_POP
147+
#define SUPPRESS_WARNING_CLANG_PUSH(warning)
148+
#define SUPPRESS_WARNING_CLANG_POP
139149
#else
140-
#define SUPPRESS_WARNING(warning, ...) __VA_ARGS__
141-
#define SUPPRESS_DEPRECATED_WARNING(...) __VA_ARGS__
142-
#define SUPPRESS_FLOAT_EQUAL_WARNING(...) __VA_ARGS__
150+
#define SUPPRESS_WARNING_PUSH(warning)
151+
#define SUPPRESS_WARNING_POP
152+
#define SUPPRESS_WARNING_GCC_PUSH(warning)
153+
#define SUPPRESS_WARNING_GCC_POP
154+
#define SUPPRESS_WARNING_CLANG_PUSH(warning)
155+
#define SUPPRESS_WARNING_CLANG_POP
143156
#endif
144157

145158
#if !defined(NO_WINDOWS_SEH) && defined(_WIN32) && defined(_MSC_VER)

lib/cppcheck.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@
6363
#include <process.h>
6464
#endif
6565

66-
#define PICOJSON_USE_INT64
67-
#include <picojson.h>
66+
#include "json.h"
6867

6968
#include <simplecpp.h>
7069

@@ -940,7 +939,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
940939

941940
#ifdef HAVE_RULES
942941
// handling of "simple" rules has been removed.
943-
if (mSimplify && hasRule("simple"))
942+
if (hasRule("simple"))
944943
throw InternalError(nullptr, "Handling of \"simple\" rules has been removed in Cppcheck. Use --addon instead.");
945944
#endif
946945

lib/cppcheck.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,6 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
224224
/** Are there too many configs? */
225225
bool mTooManyConfigs{};
226226

227-
/** Simplify code? true by default */
228-
bool mSimplify = true;
229-
230227
/** File info used for whole program analysis */
231228
std::list<Check::FileInfo*> mFileInfo;
232229

lib/cppcheck.vcxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1+
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22
<ItemGroup Label="ProjectConfigurations">
33
<ProjectConfiguration Include="Debug-PCRE|Win32">
44
<Configuration>Debug-PCRE</Configuration>
@@ -150,6 +150,7 @@
150150
<ClInclude Include="fwdanalysis.h" />
151151
<ClInclude Include="importproject.h" />
152152
<ClInclude Include="infer.h" />
153+
<ClInclude Include="json.h" />
153154
<ClInclude Include="keywords.h" />
154155
<ClInclude Include="library.h" />
155156
<ClInclude Include="mathlib.h" />

0 commit comments

Comments
 (0)