Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactorizations:

- Fixed lots of cppcheck messages about functions that can be const or static
- Fixed possible nullpointer dereference message in symboldatabase.cpp
- Replaced tokAt(+-1) by next()/previous()
  • Loading branch information...
commit 14feaa8d395f2c3161426ee628b98fc1799a5c4e 1 parent 9d88cc6
@PKEuS PKEuS authored
View
6 lib/checkother.cpp
@@ -1986,7 +1986,7 @@ bool CheckOther::isUnsigned(const Variable* var) const
{
return(var && var->typeStartToken()->isUnsigned() && !var->isPointer() && !var->isArray() && _tokenizer->sizeOfType(var->typeStartToken()) >= _settings->sizeof_int);
}
-bool CheckOther::isSigned(const Variable* var) const
+bool CheckOther::isSigned(const Variable* var)
{
return(var && !var->typeStartToken()->isUnsigned() && Token::Match(var->typeEndToken(), "int|char|short|long") && !var->isPointer() && !var->isArray());
}
@@ -2943,7 +2943,7 @@ void CheckOther::checkInvalidFree()
// as a parameter, it might be modified, so we shouldn't report an error
// if it is later used to free memory
else if (Token::Match(tok, "%var% (")) {
- const Token* tok2 = Token::findmatch(tok->tokAt(1), "%var%", tok->linkAt(1));
+ const Token* tok2 = Token::findmatch(tok->next(), "%var%", tok->linkAt(1));
while (tok2 != NULL) {
allocatedVariables.erase(tok2->varId());
tok2 = Token::findmatch(tok2->next(), "%var%", tok->linkAt(1));
@@ -3011,7 +3011,7 @@ void CheckOther::checkDoubleFree()
// of previously freed variables.
// TODO: There are false negatives. This bailout is only needed when the
// loop will exit without free()'ing the memory on the last iteration.
- else if (tok->str() == "}" && tok->link() && tok->link()->tokAt(-1) &&
+ else if (tok->str() == "}" && tok->link() && tok->link()->previous() &&
tok->link()->linkAt(-1) &&
Token::Match(tok->link()->linkAt(-1)->previous(), "while|for") &&
Token::findmatch(tok->link()->linkAt(-1), "break|continue ;", tok) != NULL) {
View
4 lib/checkother.h
@@ -155,7 +155,7 @@ class CPPCHECKLIB CheckOther : public Check {
/** @brief %Check scope of variables */
void checkVariableScope();
- bool checkInnerScope(const Token *tok, const Variable* var, bool& used);
+ static bool checkInnerScope(const Token *tok, const Variable* var, bool& used);
/** @brief %Check for constant function parameter */
void checkConstantFunctionParameter();
@@ -311,7 +311,7 @@ class CPPCHECKLIB CheckOther : public Check {
private:
bool isUnsigned(const Variable *var) const;
- bool isSigned(const Variable *var) const;
+ static bool isSigned(const Variable *var);
// Error messages..
void checkSleepTimeError(const Token *tok, const std::string &strDim);
View
2  lib/symboldatabase.cpp
@@ -1009,7 +1009,7 @@ void Variable::evaluate()
while (tok && tok->str() == "]")
tok = tok->link()->previous();
// add array dimensions if present
- if (tok->next()->str() == "[")
+ if (tok && tok->next()->str() == "[")
setFlag(fIsArray, arrayDimensions(_dimensions, tok->next()));
}
if (!tok)
View
2  lib/tokenlist.h
@@ -50,7 +50,7 @@ class CPPCHECKLIB TokenList {
void addtoken(const char str[], const unsigned int lineno, const unsigned int fileno, bool split = false);
void addtoken(const Token *tok, const unsigned int lineno, const unsigned int fileno);
- void insertTokens(Token *dest, const Token *src, unsigned int n);
+ static void insertTokens(Token *dest, const Token *src, unsigned int n);
/**
* Create tokens from code.
View
2  test/testbufferoverrun.cpp
@@ -3355,7 +3355,7 @@ class TestBufferOverrun : public TestFixture {
ASSERT_EQUALS("", errout.str());
}
- void counter_test() {
+ void counter_test() const {
std::list<const Token*> unknownParameter;
unknownParameter.push_back(0);
View
6 test/testcppcheck.cpp
@@ -58,7 +58,7 @@ class TestCppcheck : public TestFixture {
TEST_CASE(getErrorMessages);
}
- void instancesSorted() {
+ void instancesSorted() const {
for (std::list<Check *>::const_iterator i = Check::instances().begin(); i != Check::instances().end(); ++i) {
std::list<Check *>::const_iterator j = i;
++j;
@@ -68,7 +68,7 @@ class TestCppcheck : public TestFixture {
}
}
- void classInfoFormat() {
+ void classInfoFormat() const {
for (std::list<Check *>::const_iterator i = Check::instances().begin(); i != Check::instances().end(); ++i) {
const std::string info = (*i)->classInfo();
if (!info.empty()) {
@@ -80,7 +80,7 @@ class TestCppcheck : public TestFixture {
}
}
- void getErrorMessages() {
+ void getErrorMessages() const {
ErrorLogger2 errorLogger;
CppCheck cppCheck(errorLogger, true);
cppCheck.getErrorMessages();
View
34 test/testerrorlogger.cpp
@@ -54,20 +54,20 @@ class TestErrorLogger : public TestFixture {
TEST_CASE(suppressUnmatchedSuppressions);
}
- void FileLocationDefaults() {
+ void FileLocationDefaults() const {
ErrorLogger::ErrorMessage::FileLocation loc;
ASSERT_EQUALS("", loc.getfile());
ASSERT_EQUALS(0, loc.line);
}
- void FileLocationSetFile() {
+ void FileLocationSetFile() const {
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
ASSERT_EQUALS("foo.cpp", loc.getfile());
ASSERT_EQUALS(0, loc.line);
}
- void ErrorMessageConstruct() {
+ void ErrorMessageConstruct() const {
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
loc.line = 5;
@@ -81,7 +81,7 @@ class TestErrorLogger : public TestFixture {
ASSERT_EQUALS("[foo.cpp:5]: (error) Programming error.", msg.toString(true));
}
- void ErrorMessageConstructLocations() {
+ void ErrorMessageConstructLocations() const {
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
loc.line = 5;
@@ -99,7 +99,7 @@ class TestErrorLogger : public TestFixture {
ASSERT_EQUALS("[foo.cpp:5] -> [bar.cpp:8]: (error) Programming error.", msg.toString(true));
}
- void ErrorMessageVerbose() {
+ void ErrorMessageVerbose() const {
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
loc.line = 5;
@@ -113,7 +113,7 @@ class TestErrorLogger : public TestFixture {
ASSERT_EQUALS("[foo.cpp:5]: (error) Verbose error", msg.toString(true));
}
- void ErrorMessageVerboseLocations() {
+ void ErrorMessageVerboseLocations() const {
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
loc.line = 5;
@@ -131,7 +131,7 @@ class TestErrorLogger : public TestFixture {
ASSERT_EQUALS("[foo.cpp:5] -> [bar.cpp:8]: (error) Verbose error", msg.toString(true));
}
- void CustomFormat() {
+ void CustomFormat() const {
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
loc.line = 5;
@@ -145,7 +145,7 @@ class TestErrorLogger : public TestFixture {
ASSERT_EQUALS("foo.cpp:5,error,errorId,Verbose error", msg.toString(true, "{file}:{line},{severity},{id},{message}"));
}
- void CustomFormat2() {
+ void CustomFormat2() const {
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
loc.line = 5;
@@ -159,7 +159,7 @@ class TestErrorLogger : public TestFixture {
ASSERT_EQUALS("Verbose error - foo.cpp(5):(error,errorId)", msg.toString(true, "{message} - {file}({line}):({severity},{id})"));
}
- void CustomFormatLocations() {
+ void CustomFormatLocations() const {
// Check that first location from location stack is used in template
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
@@ -178,7 +178,7 @@ class TestErrorLogger : public TestFixture {
ASSERT_EQUALS("Verbose error - bar.cpp(8):(error,errorId)", msg.toString(true, "{message} - {file}({line}):({severity},{id})"));
}
- void ToXml() {
+ void ToXml() const {
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
loc.line = 5;
@@ -190,7 +190,7 @@ class TestErrorLogger : public TestFixture {
ASSERT_EQUALS("<error file=\"foo.cpp\" line=\"5\" id=\"errorId\" severity=\"error\" msg=\"Programming error.\"/>", msg.toXML(false,1));
}
- void ToXmlLocations() {
+ void ToXmlLocations() const {
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
loc.line = 5;
@@ -206,7 +206,7 @@ class TestErrorLogger : public TestFixture {
ASSERT_EQUALS("<error file=\"bar.cpp\" line=\"8\" id=\"errorId\" severity=\"error\" msg=\"Programming error.\"/>", msg.toXML(false,1));
}
- void ToVerboseXml() {
+ void ToVerboseXml() const {
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
loc.line = 5;
@@ -218,7 +218,7 @@ class TestErrorLogger : public TestFixture {
ASSERT_EQUALS("<error file=\"foo.cpp\" line=\"5\" id=\"errorId\" severity=\"error\" msg=\"Verbose error\"/>", msg.toXML(true,1));
}
- void ToVerboseXmlLocations() {
+ void ToVerboseXmlLocations() const {
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
loc.line = 5;
@@ -234,7 +234,7 @@ class TestErrorLogger : public TestFixture {
ASSERT_EQUALS("<error file=\"bar.cpp\" line=\"8\" id=\"errorId\" severity=\"error\" msg=\"Verbose error\"/>", msg.toXML(true,1));
}
- void ToXmlV2() {
+ void ToXmlV2() const {
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
loc.line = 5;
@@ -253,7 +253,7 @@ class TestErrorLogger : public TestFixture {
ASSERT_EQUALS(message, msg.toXML(false, 2));
}
- void ToXmlV2Locations() {
+ void ToXmlV2Locations() const {
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
loc.line = 5;
@@ -277,7 +277,7 @@ class TestErrorLogger : public TestFixture {
ASSERT_EQUALS(message, msg.toXML(false, 2));
}
- void InconclusiveXml() {
+ void InconclusiveXml() const {
// Location
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile("foo.cpp");
@@ -298,7 +298,7 @@ class TestErrorLogger : public TestFixture {
msg.toXML(false, 2));
}
- void SerializeInconclusiveMessage() {
+ void SerializeInconclusiveMessage() const {
// Inconclusive error message
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
ErrorMessage msg(locs, Severity::error, "Programming error", "errorId", true);
View
6 test/testmemleak.cpp
@@ -660,7 +660,7 @@ class TestMemleakInFunction : public TestFixture {
}
}
- CheckMemoryLeakInFunction checkMemoryLeak(NULL, &settings, NULL);
+ CheckMemoryLeakInFunction checkMemoryLeak(NULL, &settings, this);
checkMemoryLeak.simplifycode(tokens);
return list.front()->stringifyList(0, false);
@@ -804,7 +804,7 @@ class TestMemleakInFunction : public TestFixture {
// is there a leak in given code? if so, return the linenr
- unsigned int dofindleak(const char code[]) {
+ static unsigned int dofindleak(const char code[]) {
// Clear the error buffer..
errout.str("");
@@ -838,7 +838,7 @@ class TestMemleakInFunction : public TestFixture {
return (tok ? tok->linenr() : (unsigned int)(-1));
}
- void findleak() {
+ void findleak() const {
static const unsigned int notfound = (unsigned int)(-1);
ASSERT_EQUALS(1, dofindleak("alloc;"));
View
2  test/testsimplifytokens.cpp
@@ -7297,7 +7297,7 @@ class TestSimplifyTokens : public TestFixture {
void duplicateDefinition() { // #3565 - wrongly detects duplicate definition
const Settings settings;
- Tokenizer tokenizer(&settings, NULL);
+ Tokenizer tokenizer(&settings, this);
std::istringstream istr("x ; return a not_eq x;");
tokenizer.tokenize(istr, "test.c");
Token *x_token = tokenizer.list.front()->tokAt(5);
View
12 test/testsuppressions.cpp
@@ -45,7 +45,7 @@ class TestSuppressions : public TestFixture {
TEST_CASE(inlinesuppress_unusedFunction); // #4210 - unusedFunction
}
- void suppressionsBadId1() {
+ void suppressionsBadId1() const {
Suppressions suppressions;
std::istringstream s1("123");
ASSERT_EQUALS("Failed to add suppression. Invalid id \"123\"", suppressions.parseFile(s1));
@@ -54,7 +54,7 @@ class TestSuppressions : public TestFixture {
ASSERT_EQUALS("", suppressions.parseFile(s2));
}
- void suppressionsDosFormat() {
+ void suppressionsDosFormat() const {
Suppressions suppressions;
std::istringstream s("abc\r\ndef\r\n");
ASSERT_EQUALS("", suppressions.parseFile(s));
@@ -62,7 +62,7 @@ class TestSuppressions : public TestFixture {
ASSERT_EQUALS(true, suppressions.isSuppressed("def", "test.cpp", 1));
}
- void suppressionsFileNameWithColon() {
+ void suppressionsFileNameWithColon() const {
Suppressions suppressions;
std::istringstream s("errorid:c:\\foo.cpp\nerrorid:c:\\bar.cpp:12");
ASSERT_EQUALS("", suppressions.parseFile(s));
@@ -71,7 +71,7 @@ class TestSuppressions : public TestFixture {
ASSERT_EQUALS(true, suppressions.isSuppressed("errorid", "c:\\bar.cpp", 12));
}
- void suppressionsGlob() {
+ void suppressionsGlob() const {
// Check for syntax errors in glob
{
Suppressions suppressions;
@@ -105,7 +105,7 @@ class TestSuppressions : public TestFixture {
}
}
- void suppressionsFileNameWithExtraPath() {
+ void suppressionsFileNameWithExtraPath() const {
// Ticket #2797
Suppressions suppressions;
suppressions.addSuppression("errorid", "./a.c", 123);
@@ -313,7 +313,7 @@ class TestSuppressions : public TestFixture {
ASSERT_EQUALS("", errout.str());
}
- void inlinesuppress_unusedFunction() { // #4210 - wrong report of "unmatchedSuppression" for "unusedFunction"
+ void inlinesuppress_unusedFunction() const { // #4210 - wrong report of "unmatchedSuppression" for "unusedFunction"
Suppressions suppressions;
suppressions.addSuppression("unusedFunction", "test.c", 3U);
ASSERT_EQUALS(true, suppressions.getUnmatchedLocalSuppressions("test.c").empty());
View
6 test/testsymboldatabase.cpp
@@ -62,7 +62,7 @@ class TestSymbolDatabase: public TestFixture {
found = false;
}
- const Scope *findFunctionScopeByToken(const SymbolDatabase * db, const Token *tok) const {
+ static const Scope *findFunctionScopeByToken(const SymbolDatabase * db, const Token *tok) {
std::list<Scope>::const_iterator scope;
for (scope = db->scopeList.begin(); scope != db->scopeList.end(); ++scope) {
@@ -74,7 +74,7 @@ class TestSymbolDatabase: public TestFixture {
return 0;
}
- const Function *findFunctionByName(const std::string& str, const Scope* startScope) const {
+ static const Function *findFunctionByName(const std::string& str, const Scope* startScope) {
const Scope* currScope = startScope;
while (currScope && currScope->isExecutable()) {
if (currScope->functionOf)
@@ -196,7 +196,7 @@ class TestSymbolDatabase: public TestFixture {
TEST_CASE(findFunction1);
}
- void array() {
+ void array() const {
std::istringstream code("int a[10+2];");
TokenList list(NULL);
list.createTokens(code, "test.c");
View
88 test/testtoken.cpp
@@ -91,7 +91,7 @@ class TestToken : public TestFixture {
TEST_CASE(canFindMatchingBracketsWithTooManyOpening);
}
- void nextprevious() {
+ void nextprevious() const {
Token *token = new Token(0);
token->str("1");
token->insertToken("2");
@@ -120,7 +120,7 @@ class TestToken : public TestFixture {
return Token::Match(tokenizer.tokens(), pattern.c_str(), varid);
}
- void multiCompare() {
+ void multiCompare() const {
// Test for found
Token *one = new Token(0);
one->str("one");
@@ -172,13 +172,13 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(-1, Token::multiCompare(x, "%op%|two", "x"));
}
- void multiCompare2() { // #3294
+ void multiCompare2() const { // #3294
// Original pattern that failed: [[,(=<>+-*|&^] %num% [+-*/] %num% ]|,|)|;|=|%op%
givenACodeSampleToTokenize toks("a == 1", true);
ASSERT_EQUALS(true, Token::Match(toks.tokens(), "a =|%op%"));
}
- void multiCompare3() {
+ void multiCompare3() const {
// Original pattern that failed: "return|(|&&|%oror% %var% &&|%oror%|==|!=|<=|>=|<|>|-|%or% %var% )|&&|%oror%|;"
// Code snippet that failed: "return lv@86 |= rv@87 ;"
@@ -230,7 +230,7 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(true, Token::Match(numparen.tokens(), "(| 100 %bool%|%var%| )|"));
}
- void multiCompare4() {
+ void multiCompare4() const {
givenACodeSampleToTokenize var("std :: queue < int > foo ;");
ASSERT_EQUALS(Token::eBracket, var.tokens()->tokAt(3)->type());
@@ -241,7 +241,7 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(false, Token::Match(var.tokens(), "std :: queue %op%|x"));
}
- void getStrLength() {
+ void getStrLength() const {
Token tok(0);
tok.str("\"\"");
@@ -257,17 +257,17 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(1, (int)Token::getStrLength(&tok));
}
- void strValue() {
+ void strValue() const {
Token tok(0);
tok.str("\"\"");
- ASSERT_EQUALS(std::string(""), tok.strValue());
+ ASSERT_EQUALS("", tok.strValue());
tok.str("\"0\"");
- ASSERT_EQUALS(std::string("0"), tok.strValue());
+ ASSERT_EQUALS("0", tok.strValue());
}
- void deleteLast() {
+ void deleteLast() const {
Token *tokensBack = 0;
Token tok(&tokensBack);
tok.insertToken("aba");
@@ -276,7 +276,7 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(true, tokensBack == &tok);
}
- void nextArgument() {
+ void nextArgument() const {
givenACodeSampleToTokenize example1("foo(1, 2, 3, 4);");
ASSERT_EQUALS(true, Token::simpleMatch(example1.tokens()->tokAt(2)->nextArgument(), "2 , 3"));
@@ -287,14 +287,14 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(true, Token::simpleMatch(example3.tokens()->tokAt(2)->nextArgument(), "2 , 3"));
}
- void eraseTokens() {
+ void eraseTokens() const {
givenACodeSampleToTokenize code("begin ; { this code will be removed } end", true);
Token::eraseTokens(code.tokens()->next(), code.tokens()->tokAt(9));
ASSERT_EQUALS("begin ; end", code.tokens()->stringifyList(0, false));
}
- void matchAny() {
+ void matchAny() const {
givenACodeSampleToTokenize varBitOrVar("abc|def", true);
ASSERT_EQUALS(true, Token::Match(varBitOrVar.tokens(), "%var% | %var%"));
@@ -302,7 +302,7 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(true, Token::Match(varLogOrVar.tokens(), "%var% || %var%"));
}
- void matchSingleChar() {
+ void matchSingleChar() const {
givenACodeSampleToTokenize singleChar("a", true);
ASSERT_EQUALS(true, Token::Match(singleChar.tokens(), "[a|bc]"));
ASSERT_EQUALS(false, Token::Match(singleChar.tokens(), "[d|ef]"));
@@ -312,7 +312,7 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(false, Token::Match(&multiChar, "[ab|def]"));
}
- void matchNothingOrAnyNotElse() {
+ void matchNothingOrAnyNotElse() const {
givenACodeSampleToTokenize emptyString("", true);
ASSERT_EQUALS(true, Token::Match(emptyString.tokens(), "!!else"));
ASSERT_EQUALS(false, Token::Match(emptyString.tokens(), "!!else something"));
@@ -330,7 +330,7 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(false, Token::Match(ifSemicolonElse.tokens(), "if ; !!else"));
}
- void matchType() {
+ void matchType() const {
givenACodeSampleToTokenize type("abc", true);
ASSERT_EQUALS(true, Token::Match(type.tokens(), "%type%"));
@@ -346,7 +346,7 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(false, Token::Match(noType2.tokens(), "!!foo %type%"));
}
- void matchChar() {
+ void matchChar() const {
givenACodeSampleToTokenize chr1("'a'", true);
ASSERT_EQUALS(true, Token::Match(chr1.tokens(), "%char%"));
@@ -357,7 +357,7 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(false, Token::Match(noChr.tokens(), "%char%"));
}
- void matchCompOp() {
+ void matchCompOp() const {
givenACodeSampleToTokenize comp1("<=", true);
ASSERT_EQUALS(true, Token::Match(comp1.tokens(), "%comp%"));
@@ -368,7 +368,7 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(false, Token::Match(noComp.tokens(), "%comp%"));
}
- void matchStr() {
+ void matchStr() const {
givenACodeSampleToTokenize noStr1("abc", true);
ASSERT_EQUALS(false, Token::Match(noStr1.tokens(), "%str%"));
@@ -383,7 +383,7 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(true, Token::Match(emptyStr.tokens(), "%str%"));
}
- void matchVarid() {
+ void matchVarid() const {
givenACodeSampleToTokenize var("int a ; int b ;");
// Varid == 0 should throw exception
@@ -396,7 +396,7 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(false, Token::Match(var.tokens(), "%type% %varid% ; %type% %varid%", 2));
}
- void matchNumeric() {
+ void matchNumeric() const {
givenACodeSampleToTokenize nonNumeric("abc", true);
ASSERT_EQUALS(false, Token::Match(nonNumeric.tokens(), "%num%"));
@@ -435,7 +435,7 @@ class TestToken : public TestFixture {
}
- void matchBoolean() {
+ void matchBoolean() const {
givenACodeSampleToTokenize yes("YES", true);
ASSERT_EQUALS(false, Token::Match(yes.tokens(), "%bool%"));
@@ -446,7 +446,7 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(true, Token::Match(negative.tokens(), "%bool%"));
}
- void matchOr() {
+ void matchOr() const {
givenACodeSampleToTokenize bitwiseOr("|", true);
ASSERT_EQUALS(true, Token::Match(bitwiseOr.tokens(), "%or%"));
ASSERT_EQUALS(true, Token::Match(bitwiseOr.tokens(), "%op%"));
@@ -470,7 +470,7 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(true, Token::Match(logicalAnd.tokens(), "%oror%|&&"));
}
- void append_vector(std::vector<std::string> &dest, const std::vector<std::string> &src) const {
+ static void append_vector(std::vector<std::string> &dest, const std::vector<std::string> &src) {
dest.insert(dest.end(), src.begin(), src.end());
}
@@ -565,7 +565,7 @@ class TestToken : public TestFixture {
}
- void isArithmeticalOp() {
+ void isArithmeticalOp() const {
std::vector<std::string>::const_iterator test_op, test_ops_end = arithmeticalOps.end();
for (test_op = arithmeticalOps.begin(); test_op != test_ops_end; ++test_op) {
Token tok(NULL);
@@ -589,7 +589,7 @@ class TestToken : public TestFixture {
}
}
- void isOp() {
+ void isOp() const {
std::vector<std::string> test_ops;
append_vector(test_ops, arithmeticalOps);
append_vector(test_ops, bitOps);
@@ -616,7 +616,7 @@ class TestToken : public TestFixture {
}
}
- void isConstOp() {
+ void isConstOp() const {
std::vector<std::string> test_ops;
append_vector(test_ops, arithmeticalOps);
append_vector(test_ops, bitOps);
@@ -643,7 +643,7 @@ class TestToken : public TestFixture {
}
}
- void isExtendedOp() {
+ void isExtendedOp() const {
std::vector<std::string> test_ops;
append_vector(test_ops, arithmeticalOps);
append_vector(test_ops, bitOps);
@@ -667,7 +667,7 @@ class TestToken : public TestFixture {
}
}
- void isAssignmentOp() {
+ void isAssignmentOp() const {
std::vector<std::string>::const_iterator test_op, test_ops_end = assignmentOps.end();
for (test_op = assignmentOps.begin(); test_op != test_ops_end; ++test_op) {
Token tok(NULL);
@@ -691,7 +691,7 @@ class TestToken : public TestFixture {
}
}
- void operators() {
+ void operators() const {
std::vector<std::string>::const_iterator test_op;
for (test_op = extendedOps.begin(); test_op != extendedOps.end(); ++test_op) {
Token tok(NULL);
@@ -720,7 +720,7 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(Token::eIncDecOp, tok.type());
}
- void literals() {
+ void literals() const {
Token tok(NULL);
tok.str("\"foo\"");
@@ -739,7 +739,7 @@ class TestToken : public TestFixture {
ASSERT(tok.type() == Token::eBoolean);
}
- void isStandardType() {
+ void isStandardType() const {
std::vector<std::string> standard_types;
standard_types.push_back("bool");
standard_types.push_back("char");
@@ -767,7 +767,7 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(true, tok.isStandardType());
}
- void updateProperties() {
+ void updateProperties() const {
Token tok(NULL);
tok.str("foobar");
@@ -780,7 +780,7 @@ class TestToken : public TestFixture {
ASSERT_EQUALS(true, tok.isNumber());
}
- void updatePropertiesConcatStr() {
+ void updatePropertiesConcatStr() const {
Token tok(NULL);
tok.str("true");
@@ -792,32 +792,32 @@ class TestToken : public TestFixture {
ASSERT_EQUALS("tru23", tok.str());
}
- void isNameGuarantees1() {
+ void isNameGuarantees1() const {
Token tok(NULL);
tok.str("Name");
ASSERT_EQUALS(true, tok.isName());
}
- void isNameGuarantees2() {
+ void isNameGuarantees2() const {
Token tok(NULL);
tok.str("_name");
ASSERT_EQUALS(true, tok.isName());
}
- void isNameGuarantees3() {
+ void isNameGuarantees3() const {
Token tok(NULL);
tok.str("_123");
ASSERT_EQUALS(true, tok.isName());
}
- void isNameGuarantees4() {
+ void isNameGuarantees4() const {
Token tok(NULL);
tok.str("123456");
ASSERT_EQUALS(false, tok.isName());
ASSERT_EQUALS(true, tok.isNumber());
}
- void isNameGuarantees5() {
+ void isNameGuarantees5() const {
Token tok(NULL);
tok.str("a123456");
ASSERT_EQUALS(true, tok.isName());
@@ -825,7 +825,7 @@ class TestToken : public TestFixture {
}
- void canFindMatchingBracketsNeedsOpen() {
+ void canFindMatchingBracketsNeedsOpen() const {
givenACodeSampleToTokenize var("std::deque<std::set<int> > intsets;");
const Token* t = 0;
@@ -834,7 +834,7 @@ class TestToken : public TestFixture {
ASSERT(! t);
}
- void canFindMatchingBracketsInnerPair() {
+ void canFindMatchingBracketsInnerPair() const {
givenACodeSampleToTokenize var("std::deque<std::set<int> > intsets;");
Token* t = 0;
@@ -844,7 +844,7 @@ class TestToken : public TestFixture {
ASSERT(var.tokens()->tokAt(9) == t);
}
- void canFindMatchingBracketsOuterPair() {
+ void canFindMatchingBracketsOuterPair() const {
givenACodeSampleToTokenize var("std::deque<std::set<int> > intsets;");
const Token* t = 0;
@@ -855,7 +855,7 @@ class TestToken : public TestFixture {
}
- void canFindMatchingBracketsWithTooManyClosing() {
+ void canFindMatchingBracketsWithTooManyClosing() const {
givenACodeSampleToTokenize var("X< 1>2 > x1;\n");
const Token* t = 0;
@@ -865,7 +865,7 @@ class TestToken : public TestFixture {
ASSERT(var.tokens()->tokAt(3) == t);
}
- void canFindMatchingBracketsWithTooManyOpening() {
+ void canFindMatchingBracketsWithTooManyOpening() const {
givenACodeSampleToTokenize var("X < (2 < 1) > x1;\n");
const Token* t = 0;
View
16 test/testtokenize.cpp
@@ -4736,7 +4736,7 @@ class TestTokenizer : public TestFixture {
}
- void line1() {
+ void line1() const {
// Test for Ticket #4408
const char code[] = "#file \"c:\\a.h\"\n"
"first\n"
@@ -7865,7 +7865,7 @@ class TestTokenizer : public TestFixture {
- std::string testAst(const char code[]) {
+ static std::string testAst(const char code[]) {
// tokenize given code..
TokenList tokenList(NULL);
std::istringstream istr(code);
@@ -7878,7 +7878,7 @@ class TestTokenizer : public TestFixture {
return tokenList.front()->astTop()->astString();
}
- void astexpr() { // simple expressions with arithmetical ops
+ void astexpr() const { // simple expressions with arithmetical ops
ASSERT_EQUALS("12+3+", testAst("1+2+3"));
ASSERT_EQUALS("12*3+", testAst("1*2+3"));
ASSERT_EQUALS("123*+", testAst("1+2*3"));
@@ -7892,29 +7892,29 @@ class TestTokenizer : public TestFixture {
}
- void astpar() { // parentheses
+ void astpar() const { // parentheses
ASSERT_EQUALS("12+3*", testAst("(1+2)*3"));
ASSERT_EQUALS("123+*", testAst("1*(2+3)"));
ASSERT_EQUALS("123+*4*", testAst("1*(2+3)*4"));
}
- void astbrackets() { // []
+ void astbrackets() const { // []
ASSERT_EQUALS("123+[4+", testAst("1[2+3]+4"));
}
- void astunaryop() { // unary operators
+ void astunaryop() const { // unary operators
ASSERT_EQUALS("1a--+", testAst("1 + --a"));
ASSERT_EQUALS("1a--+", testAst("1 + a--"));
ASSERT_EQUALS("ab+!", testAst("!(a+b)"));
}
- void astfunction() { // function calls
+ void astfunction() const { // function calls
ASSERT_EQUALS("1(f+2+", testAst("1+f()+2"));
ASSERT_EQUALS("12f+3+", testAst("1+f(2)+3"));
ASSERT_EQUALS("123,f+4+", testAst("1+f(2,3)+4"));
}
- void asttemplate() { // uninstantiated templates will have <,>,etc.. how do we handle them?
+ void asttemplate() const { // uninstantiated templates will have <,>,etc.. how do we handle them?
//ASSERT_EQUALS("", testAst("a<int>()==3"));
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.