From 8cd8b9c64ebeb60ff5846d8801d1370ea3d0e12f Mon Sep 17 00:00:00 2001
From: chrchr-github <78114321+chrchr-github@users.noreply.github.com>
Date: Fri, 16 Jul 2021 21:55:12 +0200
Subject: [PATCH] Fix MSVC build and some warnings (#3334)
---
Makefile | 2 +-
cli/cli.vcxproj | 16 ++++++++--------
cli/cppcheckexecutor.cpp | 6 +++---
cli/cppcheckexecutor.h | 2 +-
cmake/compileroptions.cmake | 2 ++
lib/color.cpp | 7 +++++--
lib/color.h | 4 +++-
lib/cppcheck.vcxproj | 18 ++++++++++--------
lib/cppcheck.vcxproj.filters | 6 ++++++
lib/valueflow.cpp | 2 +-
test/testleakautovar.cpp | 10 +++++-----
test/testrunner.vcxproj | 10 +++++-----
tools/dmake.vcxproj | 2 ++
13 files changed, 52 insertions(+), 35 deletions(-)
diff --git a/Makefile b/Makefile
index b6288fcc9..431ec54bb 100644
--- a/Makefile
+++ b/Makefile
@@ -497,7 +497,7 @@ $(libcppdir)/checkvaarg.o: lib/checkvaarg.cpp lib/astutils.h lib/check.h lib/che
$(libcppdir)/clangimport.o: lib/clangimport.cpp lib/astutils.h lib/clangimport.h lib/config.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/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/clangimport.o $(libcppdir)/clangimport.cpp
-$(libcppdir)/color.o: lib/color.cpp lib/color.h
+$(libcppdir)/color.o: lib/color.cpp lib/color.h lib/config.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/color.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/astutils.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/exprengine.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
diff --git a/cli/cli.vcxproj b/cli/cli.vcxproj
index 5fb4003e4..8646760bc 100644
--- a/cli/cli.vcxproj
+++ b/cli/cli.vcxproj
@@ -163,7 +163,7 @@
CPPCHECKLIB_IMPORT;WIN32;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;%(PreprocessorDefinitions)
MultiThreadedDebugDLL
Level4
- 4018;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800
+ 4018;4127;4146;4244;4251;4267;4389;4482;4512;4701;4706;4800;4805
true
true
stdcpp14
@@ -191,7 +191,7 @@
CPPCHECKLIB_IMPORT;TINYXML2_IMPORT;WIN32;HAVE_RULES;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;TIXML_USE_STL;%(PreprocessorDefinitions)
MultiThreadedDebugDLL
Level4
- 4018;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800
+ 4018;4127;4146;4244;4251;4267;4389;4482;4512;4701;4706;4800;4805
true
true
stdcpplatest
@@ -217,7 +217,7 @@
CPPCHECKLIB_IMPORT;WIN32;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_WIN64;%(PreprocessorDefinitions)
MultiThreadedDebugDLL
Level4
- 4018;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800
+ 4018;4127;4146;4244;4251;4267;4389;4482;4512;4701;4706;4800;4805
true
true
stdcpp14
@@ -242,7 +242,7 @@
CPPCHECKLIB_IMPORT;TINYXML2_IMPORT;WIN32;HAVE_RULES;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_WIN64;%(PreprocessorDefinitions)
MultiThreadedDebugDLL
Level4
- 4018;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800
+ 4018;4127;4146;4244;4251;4267;4389;4482;4512;4701;4706;4800;4805
true
true
stdcpplatest
@@ -271,7 +271,7 @@
Speed
true
true
- 4018;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800
+ 4018;4127;4146;4244;4251;4267;4389;4482;4512;4701;4706;4800;4805
true
@@ -306,7 +306,7 @@
Speed
true
true
- 4018;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800
+ 4018;4127;4146;4244;4251;4267;4389;4482;4512;4701;4706;4800;4805
true
@@ -342,7 +342,7 @@
true
true
true
- 4018;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800
+ 4018;4127;4146;4244;4251;4267;4389;4482;4512;4701;4706;4800;4805
true
@@ -377,7 +377,7 @@
true
true
true
- 4018;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800
+ 4018;4127;4146;4244;4251;4267;4389;4482;4512;4701;4706;4800;4805
true
diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp
index f232f2b81..1e5cdb3c5 100644
--- a/cli/cppcheckexecutor.cpp
+++ b/cli/cppcheckexecutor.cpp
@@ -1176,9 +1176,9 @@ bool CppCheckExecutor::tryLoadLibrary(Library& destination, const char* basepath
* Execute a shell command and read the output from it. Returns true if command terminated successfully.
*/
// cppcheck-suppress passedByValue - "exe" copy needed in _WIN32 code
-bool CppCheckExecutor::executeCommand(std::string exe, std::vector args, const std::string &redirect, std::string *output)
+bool CppCheckExecutor::executeCommand(std::string exe, std::vector args, const std::string &redirect, std::string *output_)
{
- output->clear();
+ output_->clear();
std::string joinedArgs;
for (const std::string &arg : args) {
@@ -1204,7 +1204,7 @@ bool CppCheckExecutor::executeCommand(std::string exe, std::vector
return false;
char buffer[1024];
while (fgets(buffer, sizeof(buffer), pipe.get()) != nullptr)
- *output += buffer;
+ *output_ += buffer;
return true;
}
diff --git a/cli/cppcheckexecutor.h b/cli/cppcheckexecutor.h
index 76f903d3b..f883470e7 100644
--- a/cli/cppcheckexecutor.h
+++ b/cli/cppcheckexecutor.h
@@ -112,7 +112,7 @@ public:
/**
* Execute a shell command and read the output from it. Returns true if command terminated successfully.
*/
- static bool executeCommand(std::string exe, std::vector args, const std::string &redirect, std::string *output);
+ static bool executeCommand(std::string exe, std::vector args, const std::string &redirect, std::string *output_);
protected:
diff --git a/cmake/compileroptions.cmake b/cmake/compileroptions.cmake
index b3410a7bd..94a6d75b0 100644
--- a/cmake/compileroptions.cmake
+++ b/cmake/compileroptions.cmake
@@ -71,6 +71,7 @@ if (MSVC)
add_compile_options(/W4)
add_compile_options(/wd4018) # warning C4018: '>': signed/unsigned mismatch
add_compile_options(/wd4127) # warning C4127: conditional expression is constant
+ add_compile_options(/wd4146) # warning C4146: unary minus operator applied to unsigned type, result still unsigned
add_compile_options(/wd4244) # warning C4244: 'initializing': conversion from 'int' to 'char', possible loss of data
add_compile_options(/wd4251)
# Clang: -Wshorten-64-to-32 -Wimplicit-int-conversion
@@ -81,6 +82,7 @@ if (MSVC)
add_compile_options(/wd4701) # warning C4701: potentially uninitialized local variable 'err' used
add_compile_options(/wd4706) # warning C4706: assignment within conditional expression
add_compile_options(/wd4800) # warning C4800: 'const SymbolDatabase *' : forcing value to bool 'true' or 'false' (performance warning)
+ add_compile_options(/wd4805) # warning C4805: '==' : unsafe mix of type 'bool' and type 'long long' in operation
if (WARNINGS_ARE_ERRORS)
add_compile_options(/WX)
diff --git a/lib/color.cpp b/lib/color.cpp
index 1f4b21de1..c74127d5d 100644
--- a/lib/color.cpp
+++ b/lib/color.cpp
@@ -4,9 +4,12 @@
#endif
#include
-std::ostream& operator<<(std::ostream& os, const Color& c)
+#ifdef _WIN32
+std::ostream& operator<<(std::ostream& os, const Color& /*c*/)
+{
+#else
+std::ostream& operator<<(std::ostream & os, const Color& c)
{
-#ifndef _WIN32
static const bool use_color = isatty(STDOUT_FILENO);
if (use_color)
return os << "\033[" << static_cast(c) << "m";
diff --git a/lib/color.h b/lib/color.h
index a4632ddb0..e2e469533 100644
--- a/lib/color.h
+++ b/lib/color.h
@@ -19,6 +19,8 @@
#ifndef colorH
#define colorH
+#include "config.h"
+
#include
#include
@@ -36,7 +38,7 @@ enum class Color {
BgBlue = 44,
BgDefault = 49
};
-std::ostream& operator<<(std::ostream& os, const Color& c);
+CPPCHECKLIB std::ostream& operator<<(std::ostream& os, const Color& c);
std::string toString(const Color& c);
diff --git a/lib/cppcheck.vcxproj b/lib/cppcheck.vcxproj
index 8d44b55e9..eedb405c6 100644
--- a/lib/cppcheck.vcxproj
+++ b/lib/cppcheck.vcxproj
@@ -76,6 +76,7 @@
+
@@ -137,6 +138,7 @@
+
@@ -298,7 +300,7 @@
CPPCHECKLIB_EXPORT;TINYXML2_EXPORT;SIMPLECPP_EXPORT;WIN32;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;%(PreprocessorDefinitions)
Level4
..\externals;..\externals\picojson;..\externals\simplecpp;..\externals\tinyxml2;%(AdditionalIncludeDirectories)
- 4018;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800
+ 4018;4146;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800;4805
MultiThreadedDebugDLL
Use
precompiled.h
@@ -329,7 +331,7 @@ xcopy "$(SolutionDir)platforms" "$(OutDir)platforms" /E /I /D /Y
CPPCHECKLIB_EXPORT;TINYXML2_EXPORT;SIMPLECPP_EXPORT;WIN32;HAVE_RULES;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;TIXML_USE_STL;%(PreprocessorDefinitions)
Level4
..\externals;..\externals\picojson;..\externals\simplecpp;..\externals\tinyxml2;%(AdditionalIncludeDirectories)
- 4018;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800
+ 4018;4146;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800;4805
MultiThreadedDebugDLL
Use
precompiled.h
@@ -360,7 +362,7 @@ xcopy "$(SolutionDir)platforms" "$(OutDir)platforms" /E /I /D /Y
CPPCHECKLIB_EXPORT;TINYXML2_EXPORT;SIMPLECPP_EXPORT;WIN32;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_WIN64;%(PreprocessorDefinitions)
Level4
..\externals;..\externals\picojson;..\externals\simplecpp;..\externals\tinyxml2;%(AdditionalIncludeDirectories)
- 4018;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800
+ 4018;4146;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800;4805
MultiThreadedDebugDLL
Use
precompiled.h
@@ -389,7 +391,7 @@ xcopy "$(SolutionDir)platforms" "$(OutDir)platforms" /E /I /D /Y
CPPCHECKLIB_EXPORT;TINYXML2_EXPORT;SIMPLECPP_EXPORT;WIN32;HAVE_RULES;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_WIN64;%(PreprocessorDefinitions)
Level4
..\externals;..\externals\picojson;..\externals\simplecpp;..\externals\tinyxml2;%(AdditionalIncludeDirectories)
- 4018;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800
+ 4018;4146;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800;4805
MultiThreadedDebugDLL
Use
precompiled.h
@@ -422,7 +424,7 @@ xcopy "$(SolutionDir)platforms" "$(OutDir)platforms" /E /I /D /Y
true
true
..\externals;..\externals\picojson;..\externals\simplecpp;..\externals\tinyxml2;%(AdditionalIncludeDirectories)
- 4018;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800
+ 4018;4146;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800;4805
CPPCHECKLIB_EXPORT;TINYXML2_EXPORT;SIMPLECPP_EXPORT;NDEBUG;WIN32;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;%(PreprocessorDefinitions)
MultiThreadedDLL
@@ -462,7 +464,7 @@ xcopy "$(SolutionDir)platforms" "$(OutDir)platforms" /E /I /D /Y
true
true
..\externals;..\externals\picojson;..\externals\simplecpp;..\externals\tinyxml2;%(AdditionalIncludeDirectories)
- 4018;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800
+ 4018;4146;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800;4805
CPPCHECKLIB_EXPORT;TINYXML2_EXPORT;SIMPLECPP_EXPORT;NDEBUG;WIN32;HAVE_RULES;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;TIXML_USE_STL;%(PreprocessorDefinitions)
MultiThreadedDLL
@@ -503,7 +505,7 @@ xcopy "$(SolutionDir)platforms" "$(OutDir)platforms" /E /I /D /Y
true
true
..\externals;..\externals\picojson;..\externals\simplecpp;..\externals\tinyxml2;%(AdditionalIncludeDirectories)
- 4018;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800
+ 4018;4146;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800;4805
CPPCHECKLIB_EXPORT;TINYXML2_EXPORT;SIMPLECPP_EXPORT;NDEBUG;WIN32;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_WIN64;%(PreprocessorDefinitions)
MultiThreadedDLL
@@ -542,7 +544,7 @@ xcopy "$(SolutionDir)platforms" "$(OutDir)platforms" /E /I /D /Y
true
true
..\externals;..\externals\picojson;..\externals\simplecpp;..\externals\tinyxml2;%(AdditionalIncludeDirectories)
- 4018;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800
+ 4018;4146;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800;4805
CPPCHECKLIB_EXPORT;TINYXML2_EXPORT;SIMPLECPP_EXPORT;NDEBUG;WIN32;HAVE_RULES;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_WIN64;%(PreprocessorDefinitions)
MultiThreadedDLL
diff --git a/lib/cppcheck.vcxproj.filters b/lib/cppcheck.vcxproj.filters
index 018a50ca6..09feb4a87 100644
--- a/lib/cppcheck.vcxproj.filters
+++ b/lib/cppcheck.vcxproj.filters
@@ -188,6 +188,9 @@
Source Files
+
+ Source Files
+
@@ -367,6 +370,9 @@
Header Files
+
+ Header Files
+
diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp
index 84f7a923a..61b51a9d1 100644
--- a/lib/valueflow.cpp
+++ b/lib/valueflow.cpp
@@ -978,7 +978,7 @@ static Token * valueFlowSetConstantValue(Token *tok, const Settings *settings, b
if (!tok->isTemplateArg())
value.setKnown();
setTokenValue(tok, value, settings);
- } catch (const std::exception &e) {
+ } catch (const std::exception &/*e*/) {
// Bad character literal
}
} else if (tok->isNumber() && MathLib::isFloat(tok->str())) {
diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp
index 00290b16f..f770826d2 100644
--- a/test/testleakautovar.cpp
+++ b/test/testleakautovar.cpp
@@ -217,20 +217,20 @@ private:
c.runChecks(&tokenizer, &settings, this);
}
- void check(const char code[], Settings & settings) {
+ void check(const char code[], Settings & settings_) {
// Clear the error buffer..
errout.str("");
// Tokenize..
- Tokenizer tokenizer(&settings, this);
+ Tokenizer tokenizer(&settings_, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Check for leaks..
CheckLeakAutoVar c;
- settings.checkLibrary = true;
- settings.severity.enable(Severity::information);
- c.runChecks(&tokenizer, &settings, this);
+ settings_.checkLibrary = true;
+ settings_.severity.enable(Severity::information);
+ c.runChecks(&tokenizer, &settings_, this);
}
void assign1() {
diff --git a/test/testrunner.vcxproj b/test/testrunner.vcxproj
index 91f429a98..9dce50bcb 100755
--- a/test/testrunner.vcxproj
+++ b/test/testrunner.vcxproj
@@ -183,7 +183,7 @@
CPPCHECKLIB_IMPORT;SIMPLECPP_IMPORT;WIN32;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;%(PreprocessorDefinitions)
MultiThreadedDebugDLL
Level4
- 4018;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800
+ 4018;4127;4146;4244;4251;4267;4389;4482;4512;4701;4706;4800;4805
true
Use
precompiled.h
@@ -213,7 +213,7 @@
CPPCHECKLIB_IMPORT;SIMPLECPP_IMPORT;WIN32;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_WIN64;%(PreprocessorDefinitions)
MultiThreadedDebugDLL
Level4
- 4018;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800
+ 4018;4127;4146;4244;4251;4267;4389;4482;4512;4701;4706;4800;4805
true
Use
precompiled.h
@@ -246,7 +246,7 @@
true
true
true
- 4018;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800
+ 4018;4127;4146;4244;4251;4267;4389;4482;4512;4701;4706;4800;4805
true
@@ -285,7 +285,7 @@
true
true
true
- 4018;4127;4244;4251;4267;4389;4482;4512;4701;4706;4800
+ 4018;4127;4146;4244;4251;4267;4389;4482;4512;4701;4706;4800;4805
true
@@ -313,4 +313,4 @@
-
+
\ No newline at end of file
diff --git a/tools/dmake.vcxproj b/tools/dmake.vcxproj
index 1ce112abf..2cebf596f 100644
--- a/tools/dmake.vcxproj
+++ b/tools/dmake.vcxproj
@@ -100,6 +100,7 @@
+
@@ -107,6 +108,7 @@
+