From 12f28507772d489a37c26e8737bbadab93d1cd2e Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sun, 26 Dec 2010 23:34:00 +0200 Subject: [PATCH] Improve the message about const function. See discussion thread: https://sourceforge.net/apps/phpbb/cppcheck/viewtopic.php?f=3&t=192 --- lib/checkclass.cpp | 16 +++- test/testclass.cpp | 218 ++++++++++++++++++++++----------------------- 2 files changed, 123 insertions(+), 111 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index d0f2cdf5b..c72065c51 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1012,7 +1012,13 @@ void CheckClass::checkConst() void CheckClass::checkConstError(const Token *tok, const std::string &classname, const std::string &funcname) { - reportError(tok, Severity::information, "functionConst", "The function '" + classname + "::" + funcname + "' can be const"); + reportError(tok, Severity::information, "functionConst", + "Technically the member function '" + classname + "::" + funcname + "' can be const.\n" + "The member function '" + classname + "::" + funcname + "' can be made a const " + "function. Making this function const function should not cause compiler errors. " + "Even though the function can be made const function technically it may not make " + "sense conceptually. Think about your design and task of the function first - is " + "it a function that must not change object internal state?"); } void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname) @@ -1020,5 +1026,11 @@ void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const st std::list toks; toks.push_back(tok1); toks.push_back(tok2); - reportError(toks, Severity::information, "functionConst", "The function '" + classname + "::" + funcname + "' can be const"); + reportError(toks, Severity::information, "functionConst", + "Technically the member function '" + classname + "::" + funcname + "' can be const.\n" + "The member function '" + classname + "::" + funcname + "' can be made a const " + "function. Making this function const function should not cause compiler errors. " + "Even though the function can be made const function technically it may not make " + "sense conceptually. Think about your design and task of the function first - is " + "it a function that must not change object internal state?"); } diff --git a/test/testclass.cpp b/test/testclass.cpp index daeaafe66..4ea97b2de 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -2944,18 +2944,18 @@ private: " int a;\n" " int getA() { return a; }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3]: (information) The function 'Fred::getA' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (information) Technically the member 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]: (information) The function 'Fred::foo' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (information) Technically the member 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]: (information) The function 'Fred::foo' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (information) Technically the member 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]: (information) The function 'Fred::foo' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (information) Technically the member 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]: (information) The function 'Fred::foo' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (information) Technically the member 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]: (information) The function 'Fred::foo' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (information) Technically the member 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]: (information) The function 'Fred::foo' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (information) Technically the member 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]: (information) The function 'Fred::getA' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (information) Technically the member 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]: (information) The function 'Fred::foo' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (information) Technically the member 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]: (information) The function 'Fred::foo' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (information) Technically the member 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]: (information) The function 'Fred::foo' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (information) Technically the member 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]: (information) The function 'Fred::foo' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (information) Technically the member 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]: (information) The function 'Fred::foo' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (information) Technically the member 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]: (information) The function 'Fred::foo' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (information) Technically the member 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]: (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()); + ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (information) Technically the member function 'Fred::foo' can be const.\n" + "[test.cpp:7] -> [test.cpp:4]: (information) Technically the member 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]: (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()); + ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:3]: (information) Technically the member function 'Fred::foo1' can be const.\n" + "[test.cpp:10] -> [test.cpp:4]: (information) Technically the member function 'Fred::foo2' can be const.\n" + "[test.cpp:11] -> [test.cpp:5]: (information) Technically the member function 'Fred::foo3' can be const.\n" + "[test.cpp:12] -> [test.cpp:6]: (information) Technically the member function 'Fred::foo4' can be const.\n" + "[test.cpp:13] -> [test.cpp:7]: (information) Technically the member 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]: (information) The function 'Fred::A::getA' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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]: (information) The function 'Fred::A::getA' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:4]: (information) Technically the member 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]: (information) The function 'Fred::A::getA' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:4]: (information) Technically the member 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]: (information) The function 'Fred::B::getB' can be const\n" - "[test.cpp:7]: (information) The function 'Fred::B::A::getA' can be const\n" + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member function 'Fred::B::getB' can be const.\n" + "[test.cpp:7]: (information) Technically the member 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]: (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()); + ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:4]: (information) Technically the member function 'Fred::B::getB' can be const.\n" + "[test.cpp:9] -> [test.cpp:7]: (information) Technically the member 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]: (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()); + ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:4]: (information) Technically the member function 'Fred::B::getB' can be const.\n" + "[test.cpp:10] -> [test.cpp:7]: (information) Technically the member 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]: (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()); + ASSERT_EQUALS("[test.cpp:12] -> [test.cpp:4]: (information) Technically the member function 'Fred::B::getB' can be const.\n" + "[test.cpp:11] -> [test.cpp:7]: (information) Technically the member 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]: (information) The function 'Fred::operator<' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (information) Technically the member 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]: (information) The function 'Fred::operator[]' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (information) Technically the member 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]: (information) The function 'A::foo' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (information) Technically the member 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]: (information) The function 'Fred::foo' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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]: (information) The function 'A::strGetString' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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]: (information) The function 'A::foo' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (information) Technically the member function 'A::foo' can be const.\n", errout.str()); } void const13() @@ -3561,8 +3561,8 @@ private: " std::vector m_vec;\n" " std::pair m_pair;\n" "}"); - 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()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member function 'A::GetVec' can be const.\n" + "[test.cpp:5]: (information)Technically the member function 'A::GetPair' can be const.\n", errout.str()); checkConst("class A {\n" "public:\n" @@ -3573,8 +3573,8 @@ private: " std::vector m_vec;\n" " std::pair m_pair;\n" "}"); - 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()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member function 'A::GetVec' can be const.\n" + "[test.cpp:5]: (information) Technically the member function 'A::GetPair' can be const.\n", errout.str()); } void const14() @@ -3587,7 +3587,7 @@ private: "private:\n" " std::pair,double> m_pair;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member function 'A::GetPair' can be const.\n", errout.str()); checkConst("class A {\n" "public:\n" @@ -3596,7 +3596,7 @@ private: "private:\n" " std::pair,double> m_pair;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member function 'A::GetPair' can be const.\n", errout.str()); checkConst("class A {\n" "public:\n" @@ -3616,7 +3616,7 @@ private: "private:\n" " pair m_pair;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member function 'A::GetPair' can be const.\n", errout.str()); checkConst("using namespace std;" "class A {\n" @@ -3626,7 +3626,7 @@ private: "private:\n" " pair m_pair;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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 > m_pair;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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 > m_pair;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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 > m_pair;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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 > m_pair;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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 > m_pair;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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 > m_pair;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member function 'A::GetPair' can be const.\n", errout.str()); checkConst("using namespace std;" "class A {\n" @@ -3744,7 +3744,7 @@ private: "private:\n" " std::pair< std::vector,std::vector > m_pair;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member function 'A::GetPair' can be const.\n", errout.str()); checkConst("class A {\n" "public:\n" @@ -3764,7 +3764,7 @@ private: "private:\n" " pair< vector, vector > m_pair;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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, vector > m_pair;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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]: (information) The function 'A::GetPair' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member function 'A::GetPair' can be const.\n", errout.str()); checkConst("class A {\n" "public:\n" @@ -3913,7 +3913,7 @@ private: "private:\n" " vector m_Vec;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetVec' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member function 'A::GetVec' can be const.\n", errout.str()); checkConst("using namespace std;" "class A {\n" @@ -3923,7 +3923,7 @@ private: "private:\n" " vector m_Vec;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::GetVec' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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]: (information) The function 'A::foo' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (information) Technically the member 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]: (information) The function 'A::foo' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (information) Technically the member 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]: (information) The function 'Fred::getA' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (information) Technically the member 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 get() { return x; }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (information) The function 'Fred::get' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member function 'Fred::get' can be const.\n", errout.str()); checkConst("class Fred {\n" " std::list x;\n" @@ -4085,7 +4085,7 @@ private: "public:\n" " std::list get() { return x; }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (information) The function 'Fred::get' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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]: (information) The function 'A::strGetString' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member function 'A::strGetString' can be const.\n", errout.str()); checkConst("class A{\n" "public:\n" @@ -4201,7 +4201,7 @@ private: "std::vector m_strVec;\n" "};\n" ); - TODO_ASSERT_EQUALS("[test.cpp:4]: (information) The function 'A::strGetSize' can be const\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member 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]: (information) The function 'A::dGetValue' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:4]: (information) Technically the member 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]: (information) The function 'AA::vSetXPos' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member function 'AA::vSetXPos' can be const.\n", errout.str()); } @@ -4334,8 +4334,8 @@ private: " return b;\n" " }\n" "};\n"); - 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()); + ASSERT_EQUALS("[test.cpp:11]: (information) Technically the member function 'Derived::getA' can be const.\n" + "[test.cpp:14]: (information) Technically the member 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]: (information) The function 'Derived2::get' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (information) Technically the member 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]: (information) The function 'Derived4::get' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:10]: (information) Technically the member 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]: (information) The function 'Fred::get' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (information) Technically the member 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]: (information) The function 'N::Derived::getResourceName' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:12]: (information) Technically the member 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]: (information) The function 'N::Base::getResourceName' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:10] -> [test.cpp:6]: (information) Technically the member 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]: (information) The function 'N::Base::getResourceName' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:12] -> [test.cpp:6]: (information) Technically the member 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]: (information) The function 'N::Base::getResourceName' can be const\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:6]: (information) Technically the member 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]: (information) The function 'A::operator+' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (information) Technically the member 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]: (information) The function 'Fred::isValid' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:9]: (information) Technically the member 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]: (information) The function 'Fred::f' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:5]: (information) Technically the member 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]: (information) The function 'Fred::f' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:7]: (information) Technically the member 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]: (information) The function 'NS::Fred::f' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:10] -> [test.cpp:8]: (information) Technically the member 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]: (information) The function 'NS::Fred::f' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:8]: (information) Technically the member 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]: (information) The function 'Foo::Fred::f' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:8]: (information) Technically the member 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]: (information) The function 'Fred::a' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (information) Technically the member function 'Fred::a' can be const.\n", errout.str()); // ticket #1593 checkConst("#include \n" @@ -4845,7 +4845,7 @@ private: " A(){}\n" " unsigned int GetVecSize() {return m_v.size();}\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:7]: (information) The function 'A::GetVecSize' can be const\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:7]: (information) Technically the member 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]: (information) The function 'B::func' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (information) Technically the member 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]: (information) The function 'B::func' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:6]: (information) Technically the member 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]: (information) The function 'B::func' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:9]: (information) Technically the member 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]: (information) The function 'B::func' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:9]: (information) Technically the member 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]: (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()); + ASSERT_EQUALS("[test.cpp:5]: (information) Technically the member function 'A::func' can be const.\n" + "[test.cpp:11]: (information) Technically the member function 'B::func' can be const.\n" + "[test.cpp:17]: (information) Technically the member 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]: (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()); + ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:5]: (information) Technically the member function 'A::func' can be const.\n" + "[test.cpp:14] -> [test.cpp:12]: (information) Technically the member function 'B::func' can be const.\n" + "[test.cpp:21] -> [test.cpp:19]: (information) Technically the member 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]: (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()); + ASSERT_EQUALS("[test.cpp:5]: (information) Technically the member function 'X::getX' can be const.\n" + "[test.cpp:11]: (information) Technically the member function 'Y::getY' can be const.\n" + "[test.cpp:17]: (information) Technically the member 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]: (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()); + ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:5]: (information) Technically the member function 'X::getX' can be const.\n" + "[test.cpp:14] -> [test.cpp:12]: (information) Technically the member function 'Y::getY' can be const.\n" + "[test.cpp:21] -> [test.cpp:19]: (information) Technically the member 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]: (information) The function 'foo::f' can be const\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (information) Technically the member function 'foo::f' can be const.\n", errout.str()); settings.ifcfg = true; checkConst(code, &settings);