From 064a4aa4ccafc8138cf5ac48e0bb13245bf83496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 7 Jan 2017 14:13:22 +0100 Subject: [PATCH] improve constness of functions as per cppchecks suggestions. --- lib/checkmemoryleak.cpp | 2 +- lib/checkmemoryleak.h | 2 +- lib/tokenlist.cpp | 2 +- lib/tokenlist.h | 2 +- test/testimportproject.cpp | 6 +++--- test/testmathlib.cpp | 6 +++--- test/testpreprocessor.cpp | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index d3f402bd3..d57e3181e 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -267,7 +267,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok //-------------------------------------------------------------------------- -void CheckMemoryLeak::memoryLeak(const Token *tok, const std::string &varname, AllocType alloctype) +void CheckMemoryLeak::memoryLeak(const Token *tok, const std::string &varname, AllocType alloctype) const { if (alloctype == CheckMemoryLeak::File || alloctype == CheckMemoryLeak::Pipe || diff --git a/lib/checkmemoryleak.h b/lib/checkmemoryleak.h index 9f32b83d0..b4dc8788d 100644 --- a/lib/checkmemoryleak.h +++ b/lib/checkmemoryleak.h @@ -95,7 +95,7 @@ public: /** @brief What type of allocation are used.. the "Many" means that several types of allocation and deallocation are used */ enum AllocType { No, Malloc, New, NewArray, File, Fd, Pipe, OtherMem, OtherRes, Many }; - void memoryLeak(const Token *tok, const std::string &varname, AllocType alloctype); + void memoryLeak(const Token *tok, const std::string &varname, AllocType alloctype) const; /** * @brief Get type of deallocation at given position diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 374b24c3f..20955eee6 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1117,7 +1117,7 @@ void TokenList::createAst() } } -void TokenList::validateAst() +void TokenList::validateAst() const { // Check for some known issues in AST to avoid crash/hang later on std::set < const Token* > safeAstTokens; // list of "safe" AST tokens without endless recursion diff --git a/lib/tokenlist.h b/lib/tokenlist.h index 739f6757f..2b8becf62 100644 --- a/lib/tokenlist.h +++ b/lib/tokenlist.h @@ -139,7 +139,7 @@ public: * Check abstract syntax tree. * Throws InternalError on failure */ - void validateAst(); + void validateAst() const; /** * Verify that the given token is an element of the tokenlist. diff --git a/test/testimportproject.cpp b/test/testimportproject.cpp index 3fad76c88..9918ef41e 100644 --- a/test/testimportproject.cpp +++ b/test/testimportproject.cpp @@ -33,7 +33,7 @@ private: TEST_CASE(setIncludePaths2); } - void setDefines() { + void setDefines() const { ImportProject::FileSettings fs; fs.setDefines("A"); @@ -49,7 +49,7 @@ private: ASSERT_EQUALS("A=1;B=1", fs.defines); } - void setIncludePaths1() { + void setIncludePaths1() const { ImportProject::FileSettings fs; std::list in; in.push_back("../include"); @@ -59,7 +59,7 @@ private: ASSERT_EQUALS("abc/include/", fs.includePaths.front()); } - void setIncludePaths2() { + void setIncludePaths2() const { ImportProject::FileSettings fs; std::list in; in.push_back("$(SolutionDir)other"); diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index 82d80d428..fa0348d94 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -341,7 +341,7 @@ private: ASSERT_EQUALS(0x0A00000000000000LL, MathLib::toLongNumber("0x0A00000000000000LL")); } - void toDoubleNumber() { + void toDoubleNumber() const { ASSERT_EQUALS_DOUBLE(10.0 , MathLib::toDoubleNumber("10")); ASSERT_EQUALS_DOUBLE(1000.0, MathLib::toDoubleNumber("10E+2")); ASSERT_EQUALS_DOUBLE(100.0 , MathLib::toDoubleNumber("1.0E+2")); @@ -1133,7 +1133,7 @@ private: ASSERT_EQUALS("-0" , MathLib::toString(-0.0L)); } - void characterLiteralsNormalization() { + void characterLiteralsNormalization() const { // `A` is 0x41 and 0101 ASSERT_EQUALS("A" , MathLib::normalizeCharacterLiteral("\\x41")); ASSERT_EQUALS("A" , MathLib::normalizeCharacterLiteral("\\101")); @@ -1154,7 +1154,7 @@ private: ASSERT_THROW(MathLib::normalizeCharacterLiteral("\\c"), InternalError); } - void CPP14DigitSeparators() { // Ticket #7137, #7565 + void CPP14DigitSeparators() const { // Ticket #7137, #7565 ASSERT(MathLib::isDigitSeparator("'", 0) == false); ASSERT(MathLib::isDigitSeparator("123'0;", 3)); ASSERT(MathLib::isDigitSeparator("foo(1'2);", 5)); diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 9e7190cb9..05a2bbb53 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -1222,7 +1222,7 @@ private: ASSERT_EQUALS("\nabc ( 123 )", OurPreprocessor::expandMacros(filedata)); } - void va_args_5() { + void va_args_5() const { const char filedata1[] = "#define A(...) #__VA_ARGS__\n" "A(123)\n"; ASSERT_EQUALS("\n\"123\"", OurPreprocessor::expandMacros(filedata1));