Information: Added new severity

This commit is contained in:
Daniel Marjamäki 2010-12-22 19:53:17 +01:00
parent 22a1f3332f
commit be46d453c4
4 changed files with 120 additions and 116 deletions

View File

@ -1012,7 +1012,7 @@ void CheckClass::checkConst()
void CheckClass::checkConstError(const Token *tok, const std::string &classname, const std::string &funcname)
{
reportError(tok, Severity::style, "functionConst", "The function '" + classname + "::" + funcname + "' can be const");
reportError(tok, Severity::information, "functionConst", "The function '" + classname + "::" + funcname + "' can be const");
}
void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname)
@ -1020,5 +1020,5 @@ void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const st
std::list<const Token *> toks;
toks.push_back(tok1);
toks.push_back(tok2);
reportError(toks, Severity::style, "functionConst", "The function '" + classname + "::" + funcname + "' can be const");
reportError(toks, Severity::information, "functionConst", "The function '" + classname + "::" + funcname + "' can be const");
}

View File

@ -33,7 +33,7 @@ class Tokenizer;
class Severity
{
public:
enum SeverityType { none, error, warning, style, performance, portability, debug };
enum SeverityType { none, error, warning, style, performance, portability, information, debug };
static std::string toString(SeverityType severity)
{
switch (severity)
@ -50,6 +50,8 @@ public:
return "performance";
case portability:
return "portability";
case information:
return "information";
case debug:
return "debug";
};
@ -71,6 +73,8 @@ public:
return performance;
if (severity == "portability")
return portability;
if (severity == "information")
return information;
if (severity == "debug")
return debug;
return none;

View File

@ -1615,7 +1615,7 @@ void Preprocessor::handleIncludes(std::string &code,
// If the missing include is a system header then this is
// currently a debug-message.
const Severity::SeverityType severity = (headerType == UserHeader) ? Severity::style : Severity::debug;
const Severity::SeverityType severity = (headerType == UserHeader) ? Severity::information : Severity::debug;
const std::string id = (headerType == UserHeader) ? "missingInclude" : "debug";
ErrorLogger::ErrorMessage errmsg(locationList, severity, "Include file: \"" + filename + "\" not found.", id);
errmsg.file0 = file0;

View File

@ -2944,18 +2944,18 @@ private:
" int a;\n"
" int getA() { return a; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'Fred::getA' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (information) The function 'Fred::getA' can be const\n", errout.str());
checkConst("class Fred {\n"
" const std::string foo() { return ""; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:2]: (style) The function 'Fred::foo' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (information) The function 'Fred::foo' can be const\n", errout.str());
checkConst("class Fred {\n"
" std::string s;\n"
" const std::string & foo() { return ""; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'Fred::foo' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (information) The function 'Fred::foo' can be const\n", errout.str());
// constructors can't be const..
checkConst("class Fred {\n"
@ -3006,7 +3006,7 @@ private:
" std::string s;\n"
" void foo(std::string & a) { a = s; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'Fred::foo' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (information) The function 'Fred::foo' can be const\n", errout.str());
// assignment to variable can't be const
checkConst("class Fred {\n"
@ -3020,7 +3020,7 @@ private:
" std::string s;\n"
" void foo(std::string & a, std::string & b) { a = s; b = s; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'Fred::foo' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (information) The function 'Fred::foo' can be const\n", errout.str());
// assignment to variable, can't be const
checkConst("class Fred {\n"
@ -3051,7 +3051,7 @@ private:
" int s;\n"
" void foo(int * a) { *a = s; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'Fred::foo' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (information) The function 'Fred::foo' can be const\n", errout.str());
// assignment to variable, can't be const
checkConst("class Fred {\n"
@ -3065,7 +3065,7 @@ private:
" std::string s;\n"
" void foo(std::string * a, std::string * b) { *a = s; *b = s; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'Fred::foo' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (information) The function 'Fred::foo' can be const\n", errout.str());
// assignment to variable, can't be const
checkConst("class Fred {\n"
@ -3096,20 +3096,20 @@ private:
" int getA();\n"
"};\n"
"int Fred::getA() { return a; }");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) The function 'Fred::getA' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (information) The function 'Fred::getA' can be const\n", errout.str());
checkConst("class Fred {\n"
" const std::string foo();\n"
"};\n"
"const std::string Fred::foo() { return ""; }");
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style) The function 'Fred::foo' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (information) The function 'Fred::foo' can be const\n", errout.str());
checkConst("class Fred {\n"
" std::string s;\n"
" const std::string & foo();\n"
"};\n"
"const std::string & Fred::foo() { return ""; }");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) The function 'Fred::foo' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (information) The function 'Fred::foo' can be const\n", errout.str());
// constructors can't be const..
checkConst("class Fred {\n"
@ -3161,7 +3161,7 @@ private:
" void foo(std::string & a);\n"
"};\n"
"void Fred::foo(std::string & a) { a = s; }");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) The function 'Fred::foo' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (information) The function 'Fred::foo' can be const\n", errout.str());
// assignment to variable can't be const
checkConst("class Fred {\n"
@ -3177,7 +3177,7 @@ private:
" void foo(std::string & a, std::string & b);\n"
"};\n"
"void Fred::foo(std::string & a, std::string & b) { a = s; b = s; }");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) The function 'Fred::foo' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (information) The function 'Fred::foo' can be const\n", errout.str());
// assignment to variable, can't be const
checkConst("class Fred {\n"
@ -3209,7 +3209,7 @@ private:
" void foo(int * a);\n"
"};\n"
"void Fred::foo(int * a) { *a = s; }");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) The function 'Fred::foo' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (information) The function 'Fred::foo' can be const\n", errout.str());
// assignment to variable, can't be const
checkConst("class Fred {\n"
@ -3225,7 +3225,7 @@ private:
" void foo(std::string * a, std::string * b);\n"
"};\n"
"void Fred::foo(std::string * a, std::string * b) { *a = s; *b = s; }");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) The function 'Fred::foo' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (information) The function 'Fred::foo' can be const\n", errout.str());
// assignment to variable, can't be const
checkConst("class Fred {\n"
@ -3261,8 +3261,8 @@ private:
"void Fred::foo() { }"
"void Fred::foo(std::string & a) { a = s; }"
"void Fred::foo(const std::string & a) { s = a; }");
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (style) The function 'Fred::foo' can be const\n"
"[test.cpp:7] -> [test.cpp:4]: (style) The function 'Fred::foo' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (information) The function 'Fred::foo' can be const\n"
"[test.cpp:7] -> [test.cpp:4]: (information) The function 'Fred::foo' can be const\n", errout.str());
// check functions with different or missing parameter names
checkConst("class Fred {\n"
@ -3278,11 +3278,11 @@ private:
"void Fred::foo3(int a, int b) { }\n"
"void Fred::foo4(int a, int b) { }\n"
"void Fred::foo5(int, int) { }");
ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:3]: (style) The function 'Fred::foo1' can be const\n"
"[test.cpp:10] -> [test.cpp:4]: (style) The function 'Fred::foo2' can be const\n"
"[test.cpp:11] -> [test.cpp:5]: (style) The function 'Fred::foo3' can be const\n"
"[test.cpp:12] -> [test.cpp:6]: (style) The function 'Fred::foo4' can be const\n"
"[test.cpp:13] -> [test.cpp:7]: (style) The function 'Fred::foo5' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:3]: (information) The function 'Fred::foo1' can be const\n"
"[test.cpp:10] -> [test.cpp:4]: (information) The function 'Fred::foo2' can be const\n"
"[test.cpp:11] -> [test.cpp:5]: (information) The function 'Fred::foo3' can be const\n"
"[test.cpp:12] -> [test.cpp:6]: (information) The function 'Fred::foo4' can be const\n"
"[test.cpp:13] -> [test.cpp:7]: (information) The function 'Fred::foo5' can be const\n", errout.str());
// check nested classes
checkConst("class Fred {\n"
@ -3291,7 +3291,7 @@ private:
" int getA() { return a; }\n"
" };\n"
"};");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'Fred::A::getA' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'Fred::A::getA' can be const\n", errout.str());
checkConst("class Fred {\n"
" class A {\n"
@ -3300,7 +3300,7 @@ private:
" };\n"
" int A::getA() { return a; }\n"
"};");
ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:4]: (style) The function 'Fred::A::getA' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:4]: (information) The function 'Fred::A::getA' can be const\n", errout.str());
checkConst("class Fred {\n"
" class A {\n"
@ -3309,7 +3309,7 @@ private:
" };\n"
"};\n"
"int Fred::A::getA() { return a; }");
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:4]: (style) The function 'Fred::A::getA' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:4]: (information) The function 'Fred::A::getA' can be const\n", errout.str());
// check deeply nested classes
checkConst("class Fred {\n"
@ -3322,8 +3322,8 @@ private:
" };\n"
" };\n"
"};");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'Fred::B::getB' can be const\n"
"[test.cpp:7]: (style) The function 'Fred::B::A::getA' can be const\n"
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'Fred::B::getB' can be const\n"
"[test.cpp:7]: (information) The function 'Fred::B::A::getA' can be const\n"
, errout.str());
checkConst("class Fred {\n"
@ -3338,8 +3338,8 @@ private:
" };\n"
" int B::getB() { return b; }\n"
"};");
ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:4]: (style) The function 'Fred::B::getB' can be const\n"
"[test.cpp:9] -> [test.cpp:7]: (style) The function 'Fred::B::A::getA' can be const\n" , errout.str());
ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:4]: (information) The function 'Fred::B::getB' can be const\n"
"[test.cpp:9] -> [test.cpp:7]: (information) The function 'Fred::B::A::getA' can be const\n" , errout.str());
checkConst("class Fred {\n"
" class B {\n"
@ -3353,8 +3353,8 @@ private:
" int B::A::getA() { return a; }\n"
" int B::getB() { return b; }\n"
"};");
ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:4]: (style) The function 'Fred::B::getB' can be const\n"
"[test.cpp:10] -> [test.cpp:7]: (style) The function 'Fred::B::A::getA' can be const\n" , errout.str());
ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:4]: (information) The function 'Fred::B::getB' can be const\n"
"[test.cpp:10] -> [test.cpp:7]: (information) The function 'Fred::B::A::getA' can be const\n" , errout.str());
checkConst("class Fred {\n"
" class B {\n"
@ -3368,8 +3368,8 @@ private:
"};\n"
"int Fred::B::A::getA() { return a; }\n"
"int Fred::B::getB() { return b; }\n");
ASSERT_EQUALS("[test.cpp:12] -> [test.cpp:4]: (style) The function 'Fred::B::getB' can be const\n"
"[test.cpp:11] -> [test.cpp:7]: (style) The function 'Fred::B::A::getA' can be const\n" , errout.str());
ASSERT_EQUALS("[test.cpp:12] -> [test.cpp:4]: (information) The function 'Fred::B::getB' can be const\n"
"[test.cpp:11] -> [test.cpp:7]: (information) The function 'Fred::B::A::getA' can be const\n" , errout.str());
}
// operator< can often be const
@ -3379,7 +3379,7 @@ private:
" int a;\n"
" bool operator<(const Fred &f) { return (a < f.a); }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'Fred::operator<' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (information) The function 'Fred::operator<' can be const\n", errout.str());
}
// operator<<
@ -3411,7 +3411,7 @@ private:
" int array[10];\n"
" int const & operator [] (unsigned int index) { return array[index]; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'Fred::operator[]' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (information) The function 'Fred::operator[]' can be const\n", errout.str());
}
void const5()
@ -3426,7 +3426,7 @@ private:
" return same;\n"
" }\n"
"};");
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'A::foo' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (information) The function 'A::foo' can be const\n", errout.str());
}
void const6()
@ -3443,7 +3443,7 @@ private:
"public:\n"
" void foo() { }\n"
"};");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'Fred::foo' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'Fred::foo' can be const\n", errout.str());
checkConst("struct fast_string\n"
"{\n"
@ -3482,7 +3482,7 @@ private:
"private:\n"
" std::string m_strValue;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::strGetString' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::strGetString' can be const\n", errout.str());
}
void const9()
@ -3546,7 +3546,7 @@ private:
"private:\n"
" mutable int x;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'A::foo' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (information) The function 'A::foo' can be const\n", errout.str());
}
void const13()
@ -3561,8 +3561,8 @@ private:
" std::vector<int> m_vec;\n"
" std::pair<int,double> m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetVec' can be const\n"
"[test.cpp:5]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetVec' can be const\n"
"[test.cpp:5]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("class A {\n"
"public:\n"
@ -3573,8 +3573,8 @@ private:
" std::vector<int> m_vec;\n"
" std::pair<int,double> m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetVec' can be const\n"
"[test.cpp:5]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetVec' can be const\n"
"[test.cpp:5]: (information) The function 'A::GetPair' can be const\n", errout.str());
}
void const14()
@ -3587,7 +3587,7 @@ private:
"private:\n"
" std::pair<std::vector<int>,double> m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("class A {\n"
"public:\n"
@ -3596,7 +3596,7 @@ private:
"private:\n"
" std::pair<std::vector<int>,double> m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("class A {\n"
"public:\n"
@ -3616,7 +3616,7 @@ private:
"private:\n"
" pair<int ,double> m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("using namespace std;"
"class A {\n"
@ -3626,7 +3626,7 @@ private:
"private:\n"
" pair<int ,double> m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("using namespace std;"
"class A {\n"
@ -3646,7 +3646,7 @@ private:
"private:\n"
" std::pair< int,std::vector<int> > m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("class A {\n"
"public:\n"
@ -3655,7 +3655,7 @@ private:
"private:\n"
" std::pair< int,std::vector<int> > m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("class A {\n"
"public:\n"
@ -3675,7 +3675,7 @@ private:
"private:\n"
" pair< int,vector<int> > m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("using namespace std;"
"class A {\n"
@ -3685,7 +3685,7 @@ private:
"private:\n"
" pair< int,vector<int> > m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("using namespace std;"
"class A {\n"
@ -3706,7 +3706,7 @@ private:
"private:\n"
" pair< vector<int>, int > m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("using namespace std;"
"class A {\n"
@ -3716,7 +3716,7 @@ private:
"private:\n"
" pair< vector<int>, int > m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("using namespace std;"
"class A {\n"
@ -3735,7 +3735,7 @@ private:
"private:\n"
" std::pair< std::vector<int>,std::vector<int> > m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("class A {\n"
"public:\n"
@ -3744,7 +3744,7 @@ private:
"private:\n"
" std::pair< std::vector<int>,std::vector<int> > m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("class A {\n"
"public:\n"
@ -3764,7 +3764,7 @@ private:
"private:\n"
" pair< vector<int>, vector<int> > m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("using namespace std;"
"class A {\n"
@ -3774,7 +3774,7 @@ private:
"private:\n"
" pair< vector<int>, vector<int> > m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("using namespace std;"
"class A {\n"
@ -3795,7 +3795,7 @@ private:
"private:\n"
" std::pair< std::pair < int, char > , int > m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("class A {\n"
"public:\n"
@ -3804,7 +3804,7 @@ private:
"private:\n"
" std::pair< std::pair < int, char > , int > m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("class A {\n"
"public:\n"
@ -3823,7 +3823,7 @@ private:
"private:\n"
" pair< pair < int, char > , int > m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("using namespace std;"
"class A {\n"
@ -3833,7 +3833,7 @@ private:
"private:\n"
" pair< pair < int, char > , int > m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("using namespace std;"
"class A {\n"
@ -3854,7 +3854,7 @@ private:
"private:\n"
" pair< int , pair < int, char > > m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("using namespace std;"
"class A {\n"
@ -3864,7 +3864,7 @@ private:
"private:\n"
" pair< int , pair < int, char > > m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("using namespace std;"
@ -3884,7 +3884,7 @@ private:
"private:\n"
" std::pair< int , std::pair < int, char > > m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("class A {\n"
"public:\n"
@ -3893,7 +3893,7 @@ private:
"private:\n"
" std::pair< int , std::pair < int, char > > m_pair;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetPair' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str());
checkConst("class A {\n"
"public:\n"
@ -3913,7 +3913,7 @@ private:
"private:\n"
" vector<int> m_Vec;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetVec' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetVec' can be const\n", errout.str());
checkConst("using namespace std;"
"class A {\n"
@ -3923,7 +3923,7 @@ private:
"private:\n"
" vector<int> m_Vec;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::GetVec' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetVec' can be const\n", errout.str());
checkConst("using namespace std;"
"class A {\n"
@ -3950,7 +3950,7 @@ private:
"private:\n"
" const int * x;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'A::foo' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (information) The function 'A::foo' can be const\n", errout.str());
checkConst("class A {\n"
"public:\n"
@ -3958,7 +3958,7 @@ private:
"private:\n"
" const int * x;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'A::foo' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (information) The function 'A::foo' can be const\n", errout.str());
}
void const15()
@ -3967,7 +3967,7 @@ private:
" unsigned long long int a;\n"
" unsigned long long int getA() { return a; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'Fred::getA' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (information) The function 'Fred::getA' can be const\n", errout.str());
// constructors can't be const..
checkConst("class Fred {\n"
@ -4071,7 +4071,7 @@ private:
"public:\n"
" list<const int *> get() { return x; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'Fred::get' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'Fred::get' can be const\n", errout.str());
checkConst("class Fred {\n"
" std::list<std::string &> x;\n"
@ -4085,7 +4085,7 @@ private:
"public:\n"
" std::list<const std::string &> get() { return x; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'Fred::get' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'Fred::get' can be const\n", errout.str());
}
void const21()
@ -4178,7 +4178,7 @@ private:
"std::string m_strVal;\n"
"};\n"
);
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::strGetString' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::strGetString' can be const\n", errout.str());
checkConst("class A{\n"
"public:\n"
@ -4189,7 +4189,7 @@ private:
"std::string m_strVal;\n"
"};\n"
);
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::strGetString1' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::strGetString1' can be const\n", errout.str());
checkConst("class A{\n"
@ -4201,7 +4201,7 @@ private:
"std::vector<std::string> m_strVec;\n"
"};\n"
);
TODO_ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::strGetSize' can be const\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::strGetSize' can be const\n", errout.str());
}
void const26() // ticket #1847
@ -4234,7 +4234,7 @@ private:
" return dRet;\n"
"};\n"
);
ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:4]: (style) The function 'A::dGetValue' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:4]: (information) The function 'A::dGetValue' can be const\n", errout.str());
}
void const28() // ticket #1883
@ -4273,7 +4273,7 @@ private:
" UnknownScope::x = x_;\n"
" }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'AA::vSetXPos' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (information) The function 'AA::vSetXPos' can be const\n", errout.str());
}
@ -4315,7 +4315,7 @@ private:
" return a;\n"
" }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:7]: (style) The function 'Derived::get' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:7]: (information) The function 'Derived::get' can be const\n", errout.str());
checkConst("class Base1 {\n"
"public:\n"
@ -4334,8 +4334,8 @@ private:
" return b;\n"
" }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:11]: (style) The function 'Derived::getA' can be const\n"
"[test.cpp:14]: (style) The function 'Derived::getB' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:11]: (information) The function 'Derived::getA' can be const\n"
"[test.cpp:14]: (information) The function 'Derived::getB' can be const\n", errout.str());
checkConst("class Base {\n"
"public:\n"
@ -4348,7 +4348,7 @@ private:
" return a;\n"
" }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:8]: (style) The function 'Derived2::get' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:8]: (information) The function 'Derived2::get' can be const\n", errout.str());
checkConst("class Base {\n"
"public:\n"
@ -4363,7 +4363,7 @@ private:
" return a;\n"
" }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:10]: (style) The function 'Derived4::get' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:10]: (information) The function 'Derived4::get' can be const\n", errout.str());
// check for false positives
checkConst("class Base {\n"
@ -4434,7 +4434,7 @@ private:
" int a;\n"
" int get() { return a; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:5]: (style) The function 'Fred::get' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:5]: (information) The function 'Fred::get' can be const\n", errout.str());
}
void const32()
@ -4483,7 +4483,7 @@ private:
" int var;\n"
" };\n"
"}\n");
ASSERT_EQUALS("[test.cpp:12]: (style) The function 'N::Derived::getResourceName' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:12]: (information) The function 'N::Derived::getResourceName' can be const\n", errout.str());
checkConst("namespace N\n"
"{\n"
@ -4495,7 +4495,7 @@ private:
" };\n"
"}\n"
"int N::Base::getResourceName() { return var; }\n");
ASSERT_EQUALS("[test.cpp:10] -> [test.cpp:6]: (style) The function 'N::Base::getResourceName' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:10] -> [test.cpp:6]: (information) The function 'N::Base::getResourceName' can be const\n", errout.str());
checkConst("namespace N\n"
"{\n"
@ -4510,7 +4510,7 @@ private:
"{\n"
" int Base::getResourceName() { return var; }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:12] -> [test.cpp:6]: (style) The function 'N::Base::getResourceName' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:12] -> [test.cpp:6]: (information) The function 'N::Base::getResourceName' can be const\n", errout.str());
checkConst("namespace N\n"
"{\n"
@ -4524,7 +4524,7 @@ private:
"using namespace N;\n"
"int Base::getResourceName() { return var; }\n");
ASSERT_EQUALS("", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:6]: (style) The function 'N::Base::getResourceName' can be const\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:6]: (information) The function 'N::Base::getResourceName' can be const\n", errout.str());
}
void const36() // ticket #2003
@ -4553,7 +4553,7 @@ private:
"private:\n"
" std::string m_str;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (style) The function 'A::operator+' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:5]: (information) The function 'A::operator+' can be const\n", errout.str());
checkConst("class Fred\n"
"{\n"
@ -4567,7 +4567,7 @@ private:
" return bool(x == 0x11224488);\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:9]: (style) The function 'Fred::isValid' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:9]: (information) The function 'Fred::isValid' can be const\n", errout.str());
}
void const38() // ticket #2135
@ -4716,7 +4716,7 @@ private:
"{\n"
"}\n");
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:5]: (style) The function 'Fred::f' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:5]: (information) The function 'Fred::f' can be const\n", errout.str());
checkConst("class Fred\n"
"{\n"
@ -4730,7 +4730,7 @@ private:
"{\n"
"}\n");
ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:7]: (style) The function 'Fred::f' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:7]: (information) The function 'Fred::f' can be const\n", errout.str());
checkConst("namespace NS {\n"
" class Fred\n"
@ -4746,7 +4746,7 @@ private:
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:10] -> [test.cpp:8]: (style) The function 'NS::Fred::f' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:10] -> [test.cpp:8]: (information) The function 'NS::Fred::f' can be const\n", errout.str());
checkConst("namespace NS {\n"
" class Fred\n"
@ -4762,7 +4762,7 @@ private:
"{\n"
"}\n");
ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:8]: (style) The function 'NS::Fred::f' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:8]: (information) The function 'NS::Fred::f' can be const\n", errout.str());
checkConst("class Foo {\n"
" class Fred\n"
@ -4778,7 +4778,7 @@ private:
"{\n"
"}\n");
ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:8]: (style) The function 'Foo::Fred::f' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:8]: (information) The function 'Foo::Fred::f' can be const\n", errout.str());
}
// increment/decrement => not const
@ -4834,7 +4834,7 @@ private:
" void f() const { };\n"
" void a() { f(); };\n"
"};\n");
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'Fred::a' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (information) The function 'Fred::a' can be const\n", errout.str());
// ticket #1593
checkConst("#include <vector>\n"
@ -4845,7 +4845,7 @@ private:
" A(){}\n"
" unsigned int GetVecSize() {return m_v.size();}\n"
"}");
TODO_ASSERT_EQUALS("[test.cpp:7]: (style) The function 'A::GetVecSize' can be const\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:7]: (information) The function 'A::GetVecSize' can be const\n", errout.str());
}
void constVirtualFunc()
@ -4858,7 +4858,7 @@ private:
" B() : b(0) { }\n"
" int func() { return b; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:6]: (style) The function 'B::func' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:6]: (information) The function 'B::func' can be const\n", errout.str());
checkConst("class A { };\n"
"class B : public A {\n"
@ -4868,7 +4868,7 @@ private:
" int func();\n"
"};\n"
"int B::func() { return b; }\n");
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:6]: (style) The function 'B::func' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:6]: (information) The function 'B::func' can be const\n", errout.str());
// base class has no virtual function
checkConst("class A {\n"
@ -4881,7 +4881,7 @@ private:
" B() : b(0) { }\n"
" int func() { return b; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:9]: (style) The function 'B::func' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:9]: (information) The function 'B::func' can be const\n", errout.str());
checkConst("class A {\n"
"public:\n"
@ -4894,7 +4894,7 @@ private:
" int func();\n"
"};\n"
"int B::func() { return b; }\n");
ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:9]: (style) The function 'B::func' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:9]: (information) The function 'B::func' can be const\n", errout.str());
// base class has virtual function
checkConst("class A {\n"
@ -4954,9 +4954,9 @@ private:
" C() : c(0) { }\n"
" int func() { return c; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:5]: (style) The function 'A::func' can be const\n"
"[test.cpp:11]: (style) The function 'B::func' can be const\n"
"[test.cpp:17]: (style) The function 'C::func' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:5]: (information) The function 'A::func' can be const\n"
"[test.cpp:11]: (information) The function 'B::func' can be const\n"
"[test.cpp:17]: (information) The function 'C::func' can be const\n", errout.str());
checkConst("class A {\n"
" int a;\n"
@ -4979,9 +4979,9 @@ private:
" int func();\n"
"};\n"
"int C::func() { return c; }\n");
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:5]: (style) The function 'A::func' can be const\n"
"[test.cpp:14] -> [test.cpp:12]: (style) The function 'B::func' can be const\n"
"[test.cpp:21] -> [test.cpp:19]: (style) The function 'C::func' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:5]: (information) The function 'A::func' can be const\n"
"[test.cpp:14] -> [test.cpp:12]: (information) The function 'B::func' can be const\n"
"[test.cpp:21] -> [test.cpp:19]: (information) The function 'C::func' can be const\n", errout.str());
// base class has virtual function
checkConst("class A {\n"
@ -5046,9 +5046,9 @@ private:
" Z(int x, int y, int z) : Y(x, y), z(z) { }\n"
" int getZ() { return z; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:5]: (style) The function 'X::getX' can be const\n"
"[test.cpp:11]: (style) The function 'Y::getY' can be const\n"
"[test.cpp:17]: (style) The function 'Z::getZ' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:5]: (information) The function 'X::getX' can be const\n"
"[test.cpp:11]: (information) The function 'Y::getY' can be const\n"
"[test.cpp:17]: (information) The function 'Z::getZ' can be const\n", errout.str());
checkConst("class X {\n"
" int x;\n"
@ -5071,9 +5071,9 @@ private:
" int getZ();\n"
"};\n"
"int Z::getZ() { return z; }\n");
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:5]: (style) The function 'X::getX' can be const\n"
"[test.cpp:14] -> [test.cpp:12]: (style) The function 'Y::getY' can be const\n"
"[test.cpp:21] -> [test.cpp:19]: (style) The function 'Z::getZ' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:5]: (information) The function 'X::getX' can be const\n"
"[test.cpp:14] -> [test.cpp:12]: (information) The function 'Y::getY' can be const\n"
"[test.cpp:21] -> [test.cpp:19]: (information) The function 'Z::getZ' can be const\n", errout.str());
}
void constIfCfg()
@ -5087,7 +5087,7 @@ private:
settings.ifcfg = false;
checkConst(code, &settings);
ASSERT_EQUALS("[test.cpp:2]: (style) The function 'foo::f' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (information) The function 'foo::f' can be const\n", errout.str());
settings.ifcfg = true;
checkConst(code, &settings);