From 35e7697474b77e43173e23c97a3c03b00e926fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Mon, 27 Feb 2017 13:22:10 +0100 Subject: [PATCH] switch some functions from const to static, as cppcheck suggests. --- lib/checkio.cpp | 3 +-- lib/checkio.h | 2 +- lib/platform.h | 4 ++-- lib/settings.h | 4 ++-- lib/tokenize.cpp | 4 ++-- lib/tokenize.h | 6 +++--- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/checkio.cpp b/lib/checkio.cpp index a1cc7c682..c3f400df9 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -349,7 +349,6 @@ void CheckIO::ioWithoutPositioningError(const Token *tok) void CheckIO::readWriteOnlyFileError(const Token *tok) { - reportError(tok, Severity::error, "readWriteOnlyFile", "Read operation on a file that was opened only for writing.", CWE664, false); } @@ -2001,7 +2000,7 @@ void CheckIO::invalidPrintfArgTypeError_float(const Token* tok, unsigned int num reportError(tok, severity, "invalidPrintfArgType_float", errmsg.str(), CWE686, false); } -Severity::SeverityType CheckIO::getSeverity(const CheckIO::ArgumentInfo *argInfo) const +Severity::SeverityType CheckIO::getSeverity(const CheckIO::ArgumentInfo *argInfo) { return (argInfo && argInfo->typeToken && !argInfo->typeToken->originalName().empty()) ? Severity::portability : Severity::warning; } diff --git a/lib/checkio.h b/lib/checkio.h index ac8617807..a93e7d3be 100644 --- a/lib/checkio.h +++ b/lib/checkio.h @@ -128,7 +128,7 @@ private: void invalidLengthModifierError(const Token* tok, unsigned int numFormat, const std::string& modifier); void invalidScanfFormatWidthError(const Token* tok, unsigned int numFormat, int width, const Variable *var, char c); static void argumentType(std::ostream & s, const ArgumentInfo * argInfo); - Severity::SeverityType getSeverity(const ArgumentInfo *argInfo) const; + static Severity::SeverityType getSeverity(const ArgumentInfo *argInfo); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckIO c(nullptr, settings, errorLogger); diff --git a/lib/platform.h b/lib/platform.h index 65ba91b33..a1165567a 100644 --- a/lib/platform.h +++ b/lib/platform.h @@ -34,13 +34,13 @@ namespace cppcheck { */ class CPPCHECKLIB Platform { private: - long long min_value(int bit) const { + static long long min_value(int bit) { if (bit >= 64) return 1LL << 63; return -(1LL << (bit-1)); } - long long max_value(int bit) const { + static long long max_value(int bit) { if (bit >= 64) return (~0ULL) >> 1; return (1LL << (bit-1)) - 1LL; diff --git a/lib/settings.h b/lib/settings.h index 98ffa4fe4..936fd6955 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -100,12 +100,12 @@ public: bool verbose; /** @brief Request termination of checking */ - void terminate(bool t = true) { + static void terminate(bool t = true) { Settings::_terminated = t; } /** @brief termination requested? */ - bool terminated() const { + static bool terminated() { return Settings::_terminated; } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 138191551..bc7c18345 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7194,7 +7194,7 @@ void Tokenizer::simplifyNestedStrcat() // Check if this statement is a duplicate definition. A duplicate // definition will hide the enumerator within it's scope so just // skip the entire scope of the duplicate. -bool Tokenizer::duplicateDefinition(Token ** tokPtr) const +bool Tokenizer::duplicateDefinition(Token ** tokPtr) { // check for an end of definition const Token * tok = *tokPtr; @@ -8068,7 +8068,7 @@ const Token * Tokenizer::findGarbageCode() const return nullptr; } -bool Tokenizer::isGarbageExpr(const Token *start, const Token *end) const +bool Tokenizer::isGarbageExpr(const Token *start, const Token *end) { std::set controlFlowKeywords; controlFlowKeywords.insert("goto"); diff --git a/lib/tokenize.h b/lib/tokenize.h index b6ef154e1..10673cfad 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -582,7 +582,7 @@ private: const Token * findGarbageCode() const; /** Detect garbage expression */ - bool isGarbageExpr(const Token *start, const Token *end) const; + static bool isGarbageExpr(const Token *start, const Token *end); /** * Remove __declspec() @@ -679,7 +679,7 @@ private: /** * check for duplicate enum definition */ - bool duplicateDefinition(Token **tokPtr) const; + static bool duplicateDefinition(Token **tokPtr); /** * report error message @@ -794,7 +794,7 @@ public: */ static const Token * startOfExecutableScope(const Token * tok); - bool isMaxTime() const { + static bool isMaxTime() { #ifdef MAXTIME return (std::time(0) > maxtime); #else