diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 5192d9b72..807d31ec0 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -142,7 +142,7 @@ void CheckBufferOverrun::outOfBoundsError(const Token *tok, const std::string &w void CheckBufferOverrun::pointerOutOfBoundsError(const Token *tok, const std::string &object) { reportError(tok, Severity::portability, "pointerOutOfBounds", "Undefined behaviour: Pointer arithmetic result does not point into or just past the end of the " + object + ".\n" - "Undefined behaviour: Using pointer arithmetic so that the result does not point into or just past the end of the " + object + ". Further information: https://www.securecoding.cert.org/confluence/display/seccode/ARR30-C.+Do+not+form+or+use+out+of+bounds+pointers+or+array+subscripts"); + "Undefined behaviour: The result of this pointer arithmetic does not point into or just one element past the end of the " + object + ". Further information: https://www.securecoding.cert.org/confluence/display/seccode/ARR30-C.+Do+not+form+or+use+out+of+bounds+pointers+or+array+subscripts"); } void CheckBufferOverrun::sizeArgumentAsCharError(const Token *tok) @@ -156,22 +156,22 @@ void CheckBufferOverrun::sizeArgumentAsCharError(const Token *tok) void CheckBufferOverrun::terminateStrncpyError(const Token *tok, const std::string &varname) { reportError(tok, Severity::warning, "terminateStrncpy", - "The buffer '" + varname + "' may not be zero-terminated after the call to strncpy().\n" + "The buffer '" + varname + "' may not be null-terminated after the call to strncpy().\n" "If the source string's size fits or exceeds the given size, strncpy() does not add a " "zero at the end of the buffer. This causes bugs later in the code if the code " - "assumes buffer is zero-terminated."); + "assumes buffer is null-terminated."); } void CheckBufferOverrun::cmdLineArgsError(const Token *tok) { - reportError(tok, Severity::error, "insecureCmdLineArgs", "Buffer overrun possible for long cmd-line args."); + reportError(tok, Severity::error, "insecureCmdLineArgs", "Buffer overrun possible for long command line arguments."); } void CheckBufferOverrun::bufferNotZeroTerminatedError(const Token *tok, const std::string &varname, const std::string &function) { - const std::string errmsg = "The buffer '" + varname + "' is not zero-terminated after the call to " + function + "().\n" - "The buffer '" + varname + "' is not zero-terminated after the call to " + function + "(). " - "This will cause bugs later in the code if the code assumes the buffer is zero-terminated."; + const std::string errmsg = "The buffer '" + varname + "' is not null-terminated after the call to " + function + "().\n" + "The buffer '" + varname + "' is not null-terminated after the call to " + function + "(). " + "This will cause bugs later in the code if the code assumes the buffer is null-terminated."; reportError(tok, Severity::warning, "bufferNotZeroTerminated", errmsg, true); } @@ -2110,7 +2110,8 @@ void CheckBufferOverrun::arrayIndexThenCheckError(const Token *tok, const std::s { reportError(tok, Severity::style, "arrayIndexThenCheck", "Array index '" + indexName + "' is used before limits check.\n" - "Defensive programming: The variable '" + indexName + "' is used as array index and then there is a check that it is within limits. This can " - "mean that the array might be accessed out of bounds. Reorder conditions such as '(a[i] && i < 10)' to '(i < 10 && a[i])'. That way the " - "array will not be accessed if the index is out of limits."); + "Defensive programming: The variable '" + indexName + "' is used as an array index before it " + "is check that is within limits. This can mean that the array might be accessed out of bounds. " + "Reorder conditions such as '(a[i] && i < 10)' to '(i < 10 && a[i])'. That way the array will " + "not be accessed if the index is out of limits."); } diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 900e0537e..adbaf7ed6 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -481,8 +481,9 @@ void CheckClass::noConstructorError(const Token *tok, const std::string &classna "The " + std::string(isStruct ? "struct" : "class") + " '" + classname + "' does not have a constructor.\n" "The " + std::string(isStruct ? "struct" : "class") + " '" + classname + - " 'does not have a constructor but it has attributes. " - "The attributes are not initialized which may cause bugs or undefined behavior."); + "' does not have a constructor although it has private member variables. " + "Member variables of builtin types are left uninitialized when the class is " + "instanciated. That may cause bugs or undefined behavior."); } void CheckClass::uninitVarError(const Token *tok, const std::string &classname, const std::string &varname) @@ -492,7 +493,7 @@ void CheckClass::uninitVarError(const Token *tok, const std::string &classname, void CheckClass::operatorEqVarError(const Token *tok, const std::string &classname, const std::string &varname) { - reportError(tok, Severity::warning, "operatorEqVarError", "Member variable '" + classname + "::" + varname + "' is not assigned a value in '" + classname + "::operator=" + "'"); + reportError(tok, Severity::warning, "operatorEqVarError", "Member variable '" + classname + "::" + varname + "' is not assigned a value in '" + classname + "::operator='."); } //--------------------------------------------------------------------------- @@ -657,7 +658,7 @@ void CheckClass::privateFunctions() void CheckClass::unusedPrivateFunctionError(const Token *tok, const std::string &classname, const std::string &funcname) { - reportError(tok, Severity::style, "unusedPrivateFunction", "Unused private function '" + classname + "::" + funcname + "'"); + reportError(tok, Severity::style, "unusedPrivateFunction", "Unused private function: '" + classname + "::" + funcname + "'"); } //--------------------------------------------------------------------------- @@ -749,7 +750,7 @@ void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Sco void CheckClass::memsetError(const Token *tok, const std::string &memfunc, const std::string &classname, const std::string &type) { - reportError(tok, Severity::error, "memsetClass", "Using '" + memfunc + "' on " + type + " that contains a " + classname); + reportError(tok, Severity::error, "memsetClass", "Using '" + memfunc + "' on " + type + " that contains a " + classname + "."); } //--------------------------------------------------------------------------- @@ -790,7 +791,7 @@ void CheckClass::operatorEq() void CheckClass::operatorEqReturnError(const Token *tok, const std::string &className) { - reportError(tok, Severity::style, "operatorEq", "\'" + className + "::operator=' should return \'" + className + " &\'"); + reportError(tok, Severity::style, "operatorEq", "'" + className + "::operator=' should return '" + className + " &'."); } //--------------------------------------------------------------------------- @@ -880,7 +881,7 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co void CheckClass::operatorEqRetRefThisError(const Token *tok) { - reportError(tok, Severity::style, "operatorEqRetRefThis", "'operator=' should return reference to self"); + reportError(tok, Severity::style, "operatorEqRetRefThis", "'operator=' should return reference to 'this' instance."); } //--------------------------------------------------------------------------- @@ -1003,7 +1004,10 @@ bool CheckClass::hasAssignSelf(const Function *func, const Token *rhs) void CheckClass::operatorEqToSelfError(const Token *tok) { - reportError(tok, Severity::warning, "operatorEqToSelf", "'operator=' should check for assignment to self"); + reportError(tok, Severity::warning, "operatorEqToSelf", + "'operator=' should check for assignment to self to avoid problems with dynamic memory.\n" + "'operator=' should check for assignment to self to ensure that each block of dynamically " + "allocated memory is owned and managed by only one instance of the class."); } //--------------------------------------------------------------------------- @@ -1125,7 +1129,11 @@ void CheckClass::virtualDestructor() void CheckClass::virtualDestructorError(const Token *tok, const std::string &Base, const std::string &Derived) { - reportError(tok, Severity::error, "virtualDestructor", "Class " + Base + " which is inherited by class " + Derived + " does not have a virtual destructor"); + reportError(tok, Severity::error, "virtualDestructor", "Class '" + Base + "' which is inherited by class '" + Derived + "' does not have a virtual destructor.\n" + "Class '" + Base + "' which is inherited by class '" + Derived + "' does not have a virtual destructor. " + "If you destroy instances of the derived class by deleting a pointer that points to the base class, only " + "the destructor of the base class is executed. Thus, dynamic memory that is managed by the derived class " + "could leak. This can be avoided by adding a virtual destructor to the base class."); } //--------------------------------------------------------------------------- @@ -1152,7 +1160,7 @@ void CheckClass::thisSubtraction() void CheckClass::thisSubtractionError(const Token *tok) { - reportError(tok, Severity::warning, "thisSubtraction", "Suspicious pointer subtraction"); + reportError(tok, Severity::warning, "thisSubtraction", "Suspicious pointer subtraction. Did you intend to write '->'?"); } //--------------------------------------------------------------------------- @@ -1540,26 +1548,21 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func) void CheckClass::checkConstError(const Token *tok, const std::string &classname, const std::string &funcname) { - reportError(tok, Severity::style, "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?", true); + checkConstError2(tok, 0, classname, funcname); } void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname) { std::list toks; toks.push_back(tok1); - toks.push_back(tok2); + if (tok2) + toks.push_back(tok2); reportError(toks, Severity::style, "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. " + "function. Making this function 'const' 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 " + "sense conceptually. Think about your design and the task of the function first - is " "it a function that must not change object internal state?", true); } @@ -1644,8 +1647,10 @@ void CheckClass::initializerListError(const Token *tok1, const Token *tok2, cons toks.push_back(tok2); reportError(toks, Severity::style, "initializerList", "Member variable '" + classname + "::" + - varname + "' is in the wrong order in the initializer list.\n" - "Members are initialized in the order they are declared, not the " + varname + "' is in the wrong place in the initializer list.\n" + "Member variable '" + classname + "::" + + varname + "' is in the wrong place in the initializer list. " + "Members are initialized in the order they are declared, not in the " "order they are in the initializer list. Keeping the initializer list " "in the same order that the members were declared prevents order dependent " "initialization errors.", true); diff --git a/lib/checkexceptionsafety.h b/lib/checkexceptionsafety.h index 48a0145fc..e0bb3a672 100644 --- a/lib/checkexceptionsafety.h +++ b/lib/checkexceptionsafety.h @@ -75,24 +75,25 @@ public: private: /** Don't throw exceptions in destructors */ void destructorsError(const Token * const tok) { - reportError(tok, Severity::error, "exceptThrowInDestructor", "Throwing exception in destructor"); + reportError(tok, Severity::error, "exceptThrowInDestructor", "Exception thrown in destructor."); } void deallocThrowError(const Token * const tok, const std::string &varname) { - reportError(tok, Severity::warning, "exceptDeallocThrow", "Throwing exception in invalid state, " + varname + " points at deallocated memory"); + reportError(tok, Severity::warning, "exceptDeallocThrow", "Exception thrown in invalid state, '" + + varname + "' points at deallocated memory."); } void rethrowCopyError(const Token * const tok, const std::string &varname) { reportError(tok, Severity::style, "exceptRethrowCopy", - "Throwing a copy of the caught exception instead of rethrowing the original exception\n" - "Rethrowing an exception with 'throw " + varname + ";' makes an unnecessary copy of '" + varname + "'.\n" + "Throwing a copy of the caught exception instead of rethrowing the original exception.\n" + "Rethrowing an exception with 'throw " + varname + ";' creates an unnecessary copy of '" + varname + "'. " "To rethrow the caught exception without unnecessary copying or slicing, use a bare 'throw;'."); } void catchExceptionByValueError(const Token *tok) { reportError(tok, Severity::style, "catchExceptionByValue", "Exception should be caught by reference.\n" - "The exception is caught as a value. It could be caught " + "The exception is caught by value. It could be caught " "as a (const) reference which is usually recommended in C++."); } @@ -116,7 +117,7 @@ private: "* Throwing exceptions in destructors\n" "* Throwing exception during invalid state\n" "* Throwing a copy of a caught exception instead of rethrowing the original exception\n" - "* exception caught by value instead of by reference"; + "* Exception caught by value instead of by reference"; } }; /// @} diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index ea5afc0a2..b112e5c1c 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -1741,7 +1741,7 @@ private: } void array_index_for_continue() { - // #3913 + // #3913 check("void f() {\n" " int a[2];\n" " for (int i = 0; i < 2; ++i) {\n" @@ -3284,7 +3284,7 @@ private: " char c[6];\n" " strncpy(c,\"hello!\",sizeof(c));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'c' is not zero-terminated after the call to strncpy().\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'c' is not null-terminated after the call to strncpy().\n", errout.str()); check("void f()\n" "{\n" @@ -3323,7 +3323,7 @@ private: " strncpy(baz, bar, sizeof(baz));\n" " bar[99] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (warning) The buffer 'baz' may not be zero-terminated after the call to strncpy().\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) The buffer 'baz' may not be null-terminated after the call to strncpy().\n", errout.str()); // Test with invalid code that there is no segfault check("char baz[100];\n" @@ -3338,7 +3338,7 @@ private: " foo(baz);\n" " foo(baz);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (warning) The buffer 'baz' may not be zero-terminated after the call to strncpy().\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) The buffer 'baz' may not be null-terminated after the call to strncpy().\n", errout.str()); } void terminateStrncpy2() { @@ -3349,7 +3349,7 @@ private: " bar[99] = 0;\n" " return baz;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (warning) The buffer 'baz' may not be zero-terminated after the call to strncpy().\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) The buffer 'baz' may not be null-terminated after the call to strncpy().\n", errout.str()); } void terminateStrncpy3() { @@ -3364,7 +3364,7 @@ private: "void bar(char *p) {\n" " strncpy(p, str, 100);\n" "}\n", false); - ASSERT_EQUALS("[test.cpp:4]: (warning) The buffer 'str' may not be zero-terminated after the call to strncpy().\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) The buffer 'str' may not be null-terminated after the call to strncpy().\n", errout.str()); } void recursive_long_time() { @@ -3532,7 +3532,7 @@ private: " strcpy(prog, argv[0]);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long cmd-line args.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str()); check("int main(int argc, char* argv[])\n" "{\n" @@ -3540,7 +3540,7 @@ private: " strcat(prog, argv[0]);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long cmd-line args.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str()); check("int main(int argc, char* argv[])\n" "{\n" @@ -3548,7 +3548,7 @@ private: " sprintf(prog, \"%s\", argv[0]);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long cmd-line args.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str()); check("int main(int argc, char **argv, char **envp)\n" "{\n" @@ -3556,7 +3556,7 @@ private: " strcpy(prog, argv[0]);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long cmd-line args.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str()); check("int main(int argc, char **argv, char **envp)\n" "{\n" @@ -3564,7 +3564,7 @@ private: " strcat(prog, argv[0]);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long cmd-line args.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str()); check("int main(int argc, char **argv, char **envp)\n" "{\n" @@ -3572,7 +3572,7 @@ private: " sprintf(prog, \"%s\", argv[0]);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long cmd-line args.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str()); check("int main(int argc, char **options)\n" "{\n" @@ -3580,7 +3580,7 @@ private: " strcpy(prog, options[0]);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long cmd-line args.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str()); check("int main(int argc, char **options)\n" "{\n" @@ -3588,7 +3588,7 @@ private: " strcat(prog, options[0]);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long cmd-line args.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str()); check("int main(int argc, char **options)\n" "{\n" @@ -3596,7 +3596,7 @@ private: " sprintf(prog, \"%s\", *options);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long cmd-line args.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str()); check("int main(int argc, char **argv, char **envp)\n" "{\n" @@ -3695,21 +3695,21 @@ private: " char c[6];\n" " strncpy(c,\"hello!\",sizeof(c));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'c' is not zero-terminated after the call to strncpy().\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'c' is not null-terminated after the call to strncpy().\n", errout.str()); check("void f()\n" "{\n" " char c[6];\n" " memcpy(c,\"hello!\",sizeof(c));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'c' is not zero-terminated after the call to memcpy().\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'c' is not null-terminated after the call to memcpy().\n", errout.str()); check("void f()\n" "{\n" " char c[6];\n" " memmove(c,\"hello!\",sizeof(c));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'c' is not zero-terminated after the call to memmove().\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'c' is not null-terminated after the call to memmove().\n", errout.str()); } void readlink() { @@ -3719,7 +3719,7 @@ private: " ssize_t len = readlink(path, buf, sizeof(buf)-1);\n" " printf(\"%s\n\", buf);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'buf' is not zero-terminated after the call to readlink().\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'buf' is not null-terminated after the call to readlink().\n", errout.str()); // C only: Primitive pointer simplification check("void f()\n" @@ -3728,7 +3728,7 @@ private: " ssize_t len = readlink(path, &buf[0], sizeof(buf)-1);\n" " printf(\"%s\n\", buf);\n" "}\n", true, "test.c"); - ASSERT_EQUALS("[test.c:4]: (warning, inconclusive) The buffer 'buf' is not zero-terminated after the call to readlink().\n", errout.str()); + ASSERT_EQUALS("[test.c:4]: (warning, inconclusive) The buffer 'buf' is not null-terminated after the call to readlink().\n", errout.str()); check("void f()\n" "{\n" @@ -3774,7 +3774,7 @@ private: " ssize_t len = readlinkat(dirfd, path, buf, sizeof(buf)-1);\n" " printf(\"%s\n\", buf);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (warning, inconclusive) The buffer 'buf' is not zero-terminated after the call to readlinkat().\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (warning, inconclusive) The buffer 'buf' is not null-terminated after the call to readlinkat().\n", errout.str()); check("void f()\n" "{\n" diff --git a/test/testclass.cpp b/test/testclass.cpp index f2827b08b..1962d217c 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -188,7 +188,7 @@ private: " void goo() {}" " void operator=(const A&);\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'.\n", errout.str()); checkOpertorEq("class A\n" "{\n" @@ -222,14 +222,14 @@ private: "public:\n" " void operator=(const B&);\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'\n" - "[test.cpp:9]: (style) 'B::operator=' should return 'B &'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'.\n" + "[test.cpp:9]: (style) 'B::operator=' should return 'B &'.\n", errout.str()); checkOpertorEq("struct A\n" "{\n" " void operator=(const A&);\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) 'A::operator=' should return 'A &'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (style) 'A::operator=' should return 'A &'.\n", errout.str()); } void operatorEq2() { @@ -238,28 +238,28 @@ private: "public:\n" " void * operator=(const A&);\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'.\n", errout.str()); checkOpertorEq("class A\n" "{\n" "public:\n" " A * operator=(const A&);\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'.\n", errout.str()); checkOpertorEq("class A\n" "{\n" "public:\n" " const A & operator=(const A&);\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'.\n", errout.str()); checkOpertorEq("class A\n" "{\n" "public:\n" " B & operator=(const A&);\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'.\n", errout.str()); } void operatorEq3() { // ticket #3051 @@ -321,7 +321,7 @@ private: "public:\n" " A & operator=(const A &a) { return a; }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) 'operator=' should return reference to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); checkOpertorEqRetRefThis( "class A\n" @@ -348,7 +348,7 @@ private: " A & operator=(const A &);\n" "};\n" "A & A::operator=(const A &a) { return a; }\n"); - ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); checkOpertorEqRetRefThis( "class A\n" @@ -357,7 +357,7 @@ private: " A & operator=(const A &a);\n" "};\n" "A & A::operator=(const A &a) { return a; }\n"); - ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); checkOpertorEqRetRefThis( "class A\n" @@ -381,7 +381,7 @@ private: " B & operator=(const B &b) { return b; }\n" " };\n" "};\n"); - ASSERT_EQUALS("[test.cpp:7]: (style) 'operator=' should return reference to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); checkOpertorEqRetRefThis( "class A\n" @@ -407,7 +407,7 @@ private: " };\n" "};\n" "A::B & A::B::operator=(const A::B &b) { return b; }\n"); - ASSERT_EQUALS("[test.cpp:10]: (style) 'operator=' should return reference to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:10]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); } void operatorEqRetRefThis2() { @@ -417,7 +417,7 @@ private: "{\n" " szp &operator =(int *other) {};\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style) 'operator=' should return reference to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); checkOpertorEqRetRefThis( "class szp\n" @@ -425,7 +425,7 @@ private: " szp &operator =(int *other);\n" "};\n" "szp &szp::operator =(int *other) {}"); - ASSERT_EQUALS("[test.cpp:5]: (style) 'operator=' should return reference to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); } void operatorEqRetRefThis3() { @@ -494,7 +494,7 @@ private: "public:\n" " A & operator=(const A &a) { }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style) 'operator=' should return reference to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); checkOpertorEqRetRefThis( "class A {\n" @@ -502,7 +502,7 @@ private: " A & operator=(const A &a);\n" "};\n" "A & A :: operator=(const A &a) { }"); - ASSERT_EQUALS("[test.cpp:5]: (style) 'operator=' should return reference to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); } void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault) @@ -590,7 +590,7 @@ private: " return *this;\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:5]: (warning) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str()); // this test has an assignment test but doesn't need it checkOpertorEqToSelf( @@ -645,7 +645,7 @@ private: " s = strdup(a.s);\n" " return *this;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str()); // ticket #1224 checkOpertorEqToSelf( @@ -731,7 +731,7 @@ private: " }\n" " };\n" "};\n"); - ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str()); // this test has an assignment test but doesn't need it checkOpertorEqToSelf( @@ -802,7 +802,7 @@ private: " s = strdup(b.s);\n" " return *this;\n" " }\n"); - ASSERT_EQUALS("[test.cpp:11]: (warning) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:11]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str()); } void operatorEqToSelf3() { @@ -1236,7 +1236,7 @@ private: "private:\n" " char * data;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str()); checkOpertorEqToSelf( "class A\n" @@ -1253,7 +1253,7 @@ private: " strcpy(data, a.data);\n" " return *this;\n" "};"); - ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str()); checkOpertorEqToSelf( "class A\n" @@ -1269,7 +1269,7 @@ private: "private:\n" " char * data;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str()); checkOpertorEqToSelf( "class A\n" @@ -1286,7 +1286,7 @@ private: " *data = *a.data;\n" " return *this;\n" "};"); - ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str()); } void operatorEqToSelf7() { @@ -1383,13 +1383,13 @@ private: "class Derived : public Base { public: ~Derived() { (void)11; } };" "Base *base = new Derived;\n" "delete base;"); - ASSERT_EQUALS("[test.cpp:1]: (error) Class Base which is inherited by class Derived does not have a virtual destructor\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str()); checkVirtualDestructor("class Base { };\n" "class Derived : protected Base { public: ~Derived() { (void)11; } };" "Base *base = new Derived;\n" "delete base;"); - ASSERT_EQUALS("[test.cpp:1]: (error) Class Base which is inherited by class Derived does not have a virtual destructor\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str()); checkVirtualDestructor("class Base { };\n" "class Derived : private Base { public: ~Derived() { (void)11; } };" @@ -1411,19 +1411,19 @@ private: "class Derived : public Base { public: ~Derived() { (void)11; } };" "Base *base = new Derived;\n" "delete base;"); - ASSERT_EQUALS("[test.cpp:1]: (error) Class Base which is inherited by class Derived does not have a virtual destructor\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str()); checkVirtualDestructor("class Base { public: ~Base(); };\n" "class Derived : protected Base { public: ~Derived() { (void)11; } };" "Base *base = new Derived;\n" "delete base;"); - ASSERT_EQUALS("[test.cpp:1]: (error) Class Base which is inherited by class Derived does not have a virtual destructor\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str()); checkVirtualDestructor("class Base { public: ~Base(); };\n" "class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };" "Base *base = new Derived;\n" "delete base;"); - ASSERT_EQUALS("[test.cpp:1]: (error) Class Base which is inherited by class Derived does not have a virtual destructor\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str()); } void virtualDestructor4() { @@ -1466,7 +1466,7 @@ private: "class Derived : public Base { public: ~Derived() { (void)11; } };" "Base *base = new Derived;\n" "delete base;"); - ASSERT_EQUALS("[test.cpp:1]: (error) Class Base which is inherited by class Derived does not have a virtual destructor\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str()); checkVirtualDestructor("class Base { public: ~Base(); };\n" "class Derived : public Base { public: ~Derived() { (void)11; } };"); @@ -1580,7 +1580,7 @@ private: "public:\n" " ~B() { int a; }\n" "};\n"); - TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Class Base which is inherited by class B does not have a virtual destructor\n", + TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Class 'Base' which is inherited by class 'B' does not have a virtual destructor.\n", "", errout.str()); } @@ -1602,7 +1602,7 @@ private: "};\n" "\n" "AA *p = new B; delete p;"); - ASSERT_EQUALS("[test.cpp:9]: (error) Class AA which is inherited by class B does not have a virtual destructor\n", errout.str()); + ASSERT_EQUALS("[test.cpp:9]: (error) Class 'AA' which is inherited by class 'B' does not have a virtual destructor.\n", errout.str()); } void checkNoConstructor(const char code[]) { @@ -1728,7 +1728,7 @@ private: " Fred fred;\n" " memset(&fred, 0, sizeof(Fred));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a 'std::string'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout.str()); checkNoMemset("class Fred\n" "{\n" @@ -1739,7 +1739,7 @@ private: " Fred fred;\n" " memset(&fred, 0, sizeof(Fred));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a 'std::string'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout.str()); checkNoMemset("class Fred\n" "{\n" @@ -1760,7 +1760,7 @@ private: " Fred fred;\n" " memset(&fred, 0, sizeof(fred));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a 'std::string'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout.str()); checkNoMemset("class Fred\n" "{\n" @@ -1772,7 +1772,7 @@ private: " Pebbles pebbles;\n" " memset(&pebbles, 0, sizeof(pebbles));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:9]: (error) Using 'memset' on class that contains a 'std::string'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:9]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout.str()); checkNoMemset("class Fred\n" "{\n" @@ -1783,7 +1783,7 @@ private: " Fred fred;\n" " memset(&fred, 0, sizeof(fred));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a virtual method\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a virtual method.\n", errout.str()); checkNoMemset("class Fred\n" "{\n" @@ -1794,7 +1794,7 @@ private: " static Fred fred;\n" " memset(&fred, 0, sizeof(fred));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a virtual method\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a virtual method.\n", errout.str()); checkNoMemset("class Fred\n" "{\n" @@ -1809,7 +1809,7 @@ private: " Pebbles pebbles;\n" " memset(&pebbles, 0, sizeof(pebbles));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:12]: (error) Using 'memset' on class that contains a virtual method\n", errout.str()); + ASSERT_EQUALS("[test.cpp:12]: (error) Using 'memset' on class that contains a virtual method.\n", errout.str()); // Fred not defined in scope checkNoMemset("namespace n1 {\n" @@ -1837,7 +1837,7 @@ private: " n1::Fred fred;\n" " memset(&fred, 0, sizeof(n1::Fred));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on class that contains a 'std::string'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout.str()); // Fred with namespace qualifier checkNoMemset("namespace n1 {\n" @@ -1851,7 +1851,7 @@ private: " n1::Fred fred;\n" " memset(&fred, 0, sizeof(fred));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on class that contains a 'std::string'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout.str()); } void memsetOnStruct() { @@ -1903,7 +1903,7 @@ private: " struct A fail;\n" " memset(&fail, 0, sizeof(struct A));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on struct that contains a 'std::string'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout.str()); checkNoMemset("struct Fred\n" "{\n" @@ -1914,7 +1914,7 @@ private: " Fred fred;\n" " memset(&fred, 0, sizeof(fred));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on struct that contains a 'std::string'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout.str()); checkNoMemset("struct Stringy {\n" " std::string inner;\n" @@ -1927,7 +1927,7 @@ private: " memset(&foo, 0, sizeof(Foo));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:9]: (error) Using 'memset' on struct that contains a 'std::string'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:9]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout.str()); } void memsetVector() { @@ -1939,7 +1939,7 @@ private: " A a;\n" " memset(&a, 0, sizeof(A));\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on class that contains a 'std::vector'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on class that contains a 'std::vector'.\n", errout.str()); checkNoMemset("struct A\n" "{ std::vector ints; };\n" @@ -1949,7 +1949,7 @@ private: " A a;\n" " memset(&a, 0, sizeof(A));\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'.\n", errout.str()); checkNoMemset("struct A\n" "{ std::vector ints; };\n" @@ -1959,7 +1959,7 @@ private: " A a;\n" " memset(&a, 0, sizeof(struct A));\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'.\n", errout.str()); checkNoMemset("struct A\n" "{ std::vector ints; };\n" @@ -1969,7 +1969,7 @@ private: " A a;\n" " memset(&a, 0, sizeof(a));\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'.\n", errout.str()); checkNoMemset("class A\n" "{ std::vector< std::vector > ints; };\n" @@ -1979,7 +1979,7 @@ private: " A a;\n" " memset(&a, 0, sizeof(A));\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on class that contains a 'std::vector'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on class that contains a 'std::vector'.\n", errout.str()); checkNoMemset("struct A\n" "{ std::vector< std::vector > ints; };\n" @@ -1989,7 +1989,7 @@ private: " A a;\n" " memset(&a, 0, sizeof(A));\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'.\n", errout.str()); checkNoMemset("struct A\n" "{ std::vector< std::vector > ints; };\n" @@ -1999,7 +1999,7 @@ private: " A a;\n" " memset(&a, 0, sizeof(a));\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'.\n", errout.str()); checkNoMemset("struct A\n" "{ std::vector ints; };\n" @@ -2009,7 +2009,7 @@ private: " A a;\n" " memset(&a, 0, sizeof(A));\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'.\n", errout.str()); } @@ -2033,20 +2033,20 @@ private: void this_subtraction() { checkThisSubtraction("; this-x ;"); - ASSERT_EQUALS("[test.cpp:1]: (warning) Suspicious pointer subtraction\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?\n", errout.str()); checkThisSubtraction("; *this = *this-x ;"); ASSERT_EQUALS("", errout.str()); checkThisSubtraction("; *this = *this-x ;\n" "this-x ;"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious pointer subtraction\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?\n", errout.str()); checkThisSubtraction("; *this = *this-x ;\n" "this-x ;\n" "this-x ;\n"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious pointer subtraction\n" - "[test.cpp:3]: (warning) Suspicious pointer subtraction\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?\n" + "[test.cpp:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?\n", errout.str()); } void checkConst(const char code[], const Settings *s = 0, bool inconclusive = true) { @@ -5099,8 +5099,8 @@ private: "public:\n" " Fred() : c(0), b(0), a(0) { }\n" "};"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Member variable 'Fred::b' is in the wrong order in the initializer list.\n" - "[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Member variable 'Fred::a' is in the wrong order in the initializer list.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list.\n" + "[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list.\n", errout.str()); } void checkInitializationListUsage(const char code[]) { diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 63bcbe7ca..769ecea54 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -343,7 +343,7 @@ private: " void operator=(const Fred &fred) { }\n" " int i;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='.\n", errout.str()); } void initvar_operator_eq3() { @@ -372,7 +372,7 @@ private: " return *this\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='.\n", errout.str()); check("class Fred\n" "{\n" @@ -387,7 +387,7 @@ private: " return *this\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='.\n", errout.str()); check("class Fred\n" "{\n" @@ -402,7 +402,7 @@ private: " return *this\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='.\n", errout.str()); check("class Fred\n" "{\n" @@ -812,7 +812,7 @@ private: " const A& operator=(const A&){return *this;}\n" "};\n"); ASSERT_EQUALS("[test.cpp:12]: (warning) Member variable 'A::m_SemVar' is not initialized in the constructor.\n" - "[test.cpp:13]: (warning) Member variable 'A::m_SemVar' is not assigned a value in 'A::operator='\n", errout.str()); + "[test.cpp:13]: (warning) Member variable 'A::m_SemVar' is not assigned a value in 'A::operator='.\n", errout.str()); check("class A\n" "{\n" @@ -823,7 +823,7 @@ private: " const A& operator=(const A&){return *this;}\n" "};\n"); ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'A::m_SemVar' is not initialized in the constructor.\n" - "[test.cpp:7]: (warning) Member variable 'A::m_SemVar' is not assigned a value in 'A::operator='\n", errout.str()); + "[test.cpp:7]: (warning) Member variable 'A::m_SemVar' is not assigned a value in 'A::operator='.\n", errout.str()); } void initvar_nocopy2() { // ticket #2484 @@ -857,7 +857,7 @@ private: " const A& operator=(const A&){return *this;}\n" "};\n"); ASSERT_EQUALS("[test.cpp:12]: (warning) Member variable 'A::m_SemVar' is not initialized in the constructor.\n" - "[test.cpp:13]: (warning) Member variable 'A::m_SemVar' is not assigned a value in 'A::operator='\n", errout.str()); + "[test.cpp:13]: (warning) Member variable 'A::m_SemVar' is not assigned a value in 'A::operator='.\n", errout.str()); } void initvar_destructor() { @@ -887,7 +887,7 @@ private: "\n" "void Fred::operator=(const Fred &f)\n" "{ }", true); - ASSERT_EQUALS("[test.cpp:13]: (warning) Member variable 'Fred::ints' is not assigned a value in 'Fred::operator='\n", errout.str()); + ASSERT_EQUALS("[test.cpp:13]: (warning) Member variable 'Fred::ints' is not assigned a value in 'Fred::operator='.\n", errout.str()); } void uninitVar1() { @@ -1045,7 +1045,7 @@ private: " }\n" " return *this;\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (warning) Member variable 'Foo::a' is not assigned a value in 'Foo::operator='\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (warning) Member variable 'Foo::a' is not assigned a value in 'Foo::operator='.\n", errout.str()); } void uninitVar9() { // ticket #1730 @@ -1504,7 +1504,7 @@ private: "Fred & Fred::clone(const Fred & other) {\n" " return *this;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'Fred::x' is not assigned a value in 'Fred::operator='\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'Fred::x' is not assigned a value in 'Fred::operator='.\n", errout.str()); } void uninitVarArray1() { @@ -2325,7 +2325,7 @@ private: " }\n" "};"); ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'A::a' is not initialized in the constructor.\n" - "[test.cpp:5]: (warning) Member variable 'A::a' is not assigned a value in 'A::operator='\n", errout.str()); + "[test.cpp:5]: (warning) Member variable 'A::a' is not assigned a value in 'A::operator='.\n", errout.str()); } void uninitVarPointer() { // #3801 @@ -2375,7 +2375,7 @@ private: " A* const a;\n" " B& operator=(const B& r) { }\n" "};"); - TODO_ASSERT_EQUALS("", "[test.cpp:4]: (warning) Member variable 'B::a' is not assigned a value in 'B::operator='\n", errout.str()); // #3804 + TODO_ASSERT_EQUALS("", "[test.cpp:4]: (warning) Member variable 'B::a' is not assigned a value in 'B::operator='.\n", errout.str()); // #3804 check("struct B {\n" " const int a;\n" diff --git a/test/testexceptionsafety.cpp b/test/testexceptionsafety.cpp index ba35483db..005e78a7f 100644 --- a/test/testexceptionsafety.cpp +++ b/test/testexceptionsafety.cpp @@ -68,7 +68,7 @@ private: " throw e;\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (error) Throwing exception in destructor\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Exception thrown in destructor.\n", errout.str()); check("class x {\n" " ~x();\n" @@ -76,14 +76,14 @@ private: "x::~x() {\n" " throw e;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Throwing exception in destructor\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (error) Exception thrown in destructor.\n", errout.str()); check("x::~x() {\n" " throw e;\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Throwing exception in destructor\n", "", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Exception thrown in destructor.\n", "", errout.str()); - // #3858 - throwing exception in try block in destructor + // #3858 - throwing exception in try block in destructor. check("class x {\n" " ~x() {\n" " try {\n" @@ -103,7 +103,7 @@ private: " throw 123;\n" " p = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Throwing exception in invalid state, p points at deallocated memory\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory.\n", errout.str()); check("void f() {\n" " static int* p = foo;\n" @@ -112,7 +112,7 @@ private: " throw 1;\n" " p = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Throwing exception in invalid state, p points at deallocated memory\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory.\n", errout.str()); } void deallocThrow2() { @@ -147,7 +147,7 @@ private: " delete p;\n" " throw 1;\n" "}", true); - ASSERT_EQUALS("[test.cpp:4]: (warning) Throwing exception in invalid state, p points at deallocated memory\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory.\n", errout.str()); } void rethrowCopy1() { @@ -161,7 +161,7 @@ private: " throw err;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception.\n", errout.str()); } void rethrowCopy2() { @@ -175,7 +175,7 @@ private: " throw err;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception.\n", errout.str()); } void rethrowCopy3() { @@ -187,7 +187,7 @@ private: " throw err;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception.\n", errout.str()); } void rethrowCopy4() { @@ -219,7 +219,7 @@ private: " }\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:10]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception\n", errout.str()); + ASSERT_EQUALS("[test.cpp:10]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception.\n", errout.str()); check("void f() {\n" " try {\n"