Message refactorization: checkassignif.cpp, checkautovariables.cpp
This commit is contained in:
parent
43c060b630
commit
0f1cb4c98c
|
@ -72,7 +72,7 @@ void CheckAssignIf::assignIfError(const Token *tok, bool result)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::style,
|
reportError(tok, Severity::style,
|
||||||
"assignIfError",
|
"assignIfError",
|
||||||
"Mismatching assignment and comparison, comparison is always " + std::string(result ? "true" : "false"));
|
"Mismatching assignment and comparison, comparison is always " + std::string(result ? "true" : "false") + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ void CheckAssignIf::comparisonError(const Token *tok, MathLib::bigint value1, co
|
||||||
std::ostringstream expression;
|
std::ostringstream expression;
|
||||||
expression << std::hex << "(X & 0x" << value1 << ") " << op << " 0x" << value2;
|
expression << std::hex << "(X & 0x" << value1 << ") " << op << " 0x" << value2;
|
||||||
|
|
||||||
const std::string errmsg("Expression '" + expression.str() + "' is always " + (result?"true":"false") + "\n"
|
const std::string errmsg("Expression '" + expression.str() + "' is always " + (result?"true":"false") + ".\n"
|
||||||
"The expression '" + expression.str() + "' is always " + (result?"true":"false") +
|
"The expression '" + expression.str() + "' is always " + (result?"true":"false") +
|
||||||
". Check carefully constants and operators used, these errors might be hard to "
|
". Check carefully constants and operators used, these errors might be hard to "
|
||||||
"spot sometimes. In case of complex expression it might help to split it to "
|
"spot sometimes. In case of complex expression it might help to split it to "
|
||||||
|
@ -177,8 +177,8 @@ void CheckAssignIf::multiCondition()
|
||||||
void CheckAssignIf::multiConditionError(const Token *tok, unsigned int line1)
|
void CheckAssignIf::multiConditionError(const Token *tok, unsigned int line1)
|
||||||
{
|
{
|
||||||
std::ostringstream errmsg;
|
std::ostringstream errmsg;
|
||||||
errmsg << "'else if' condition matches previous condition at line "
|
errmsg << "Expression is always false because 'else if' condition matches previous condition at line "
|
||||||
<< line1;
|
<< line1 << ".";
|
||||||
|
|
||||||
reportError(tok, Severity::style, "multiCondition", errmsg.str());
|
reportError(tok, Severity::style, "multiCondition", errmsg.str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,28 +188,28 @@ void CheckAutoVariables::returnPointerToLocalArray()
|
||||||
|
|
||||||
void CheckAutoVariables::errorReturnAddressToAutoVariable(const Token *tok)
|
void CheckAutoVariables::errorReturnAddressToAutoVariable(const Token *tok)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::error, "returnAddressOfAutoVariable", "Return of the address of an auto-variable");
|
reportError(tok, Severity::error, "returnAddressOfAutoVariable", "Address of an auto-variable returned.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckAutoVariables::errorReturnPointerToLocalArray(const Token *tok)
|
void CheckAutoVariables::errorReturnPointerToLocalArray(const Token *tok)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::error, "returnLocalVariable", "Returning pointer to local array variable");
|
reportError(tok, Severity::error, "returnLocalVariable", "Pointer to local array variable returned.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckAutoVariables::errorAutoVariableAssignment(const Token *tok, bool inconclusive)
|
void CheckAutoVariables::errorAutoVariableAssignment(const Token *tok, bool inconclusive)
|
||||||
{
|
{
|
||||||
if (!inconclusive) {
|
if (!inconclusive) {
|
||||||
reportError(tok, Severity::error, "autoVariables",
|
reportError(tok, Severity::error, "autoVariables",
|
||||||
"Assigning address of local auto-variable to a function parameter.\n"
|
"Address of local auto-variable assigned to a function parameter.\n"
|
||||||
"Dangerous assignment - function parameter takes the address of a local "
|
"Dangerous assignment - function parameter is assigned the address of a local "
|
||||||
"auto-variable. Local auto-variables are reserved from the stack. And the "
|
"auto-variable. Local auto-variables are reserved from the stack which "
|
||||||
"stack is freed when the function ends. So the pointer to a local variable "
|
"is freed when the function ends. So the pointer to a local variable "
|
||||||
"is invalid after the function ends.");
|
"is invalid after the function ends.");
|
||||||
} else {
|
} else {
|
||||||
reportError(tok, Severity::error, "autoVariables",
|
reportError(tok, Severity::error, "autoVariables",
|
||||||
"Assigning address of local auto-variable to a function parameter.\n"
|
"Address of local auto-variable assigned to a function parameter.\n"
|
||||||
"Function parameter takes the address of a local auto-variable. "
|
"Function parameter is assigned the address of a local auto-variable. "
|
||||||
"Local auto-variables are reserved from the stack. And the stack is freed when "
|
"Local auto-variables are reserved from the stack which is freed when "
|
||||||
"the function ends. The address is invalid after the function ends and it "
|
"the function ends. The address is invalid after the function ends and it "
|
||||||
"might 'leak' from the function through the parameter.", true);
|
"might 'leak' from the function through the parameter.", true);
|
||||||
}
|
}
|
||||||
|
@ -218,9 +218,10 @@ void CheckAutoVariables::errorAutoVariableAssignment(const Token *tok, bool inco
|
||||||
void CheckAutoVariables::errorReturnAddressOfFunctionParameter(const Token *tok, const std::string &varname)
|
void CheckAutoVariables::errorReturnAddressOfFunctionParameter(const Token *tok, const std::string &varname)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::error, "returnAddressOfFunctionParameter",
|
reportError(tok, Severity::error, "returnAddressOfFunctionParameter",
|
||||||
"Return the address of function parameter '" + varname + "'\n"
|
"Address of function parameter '" + varname + "' returned.\n"
|
||||||
"Address of the function parameter '" + varname + "' is invalid after the function exits. "
|
"Address of the function parameter '" + varname + "' becomes invalid after the function exits because "
|
||||||
"Function parameters are created into the stack. When the function exits the stack is deleted.");
|
"function parameters are stored on the stack which is freed when the function exits. Thus the returned "
|
||||||
|
"value is invalid.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -288,12 +289,12 @@ void CheckAutoVariables::returnReference()
|
||||||
|
|
||||||
void CheckAutoVariables::errorReturnReference(const Token *tok)
|
void CheckAutoVariables::errorReturnReference(const Token *tok)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::error, "returnReference", "Returning reference to auto variable");
|
reportError(tok, Severity::error, "returnReference", "Reference to auto variable returned.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckAutoVariables::errorReturnTempReference(const Token *tok)
|
void CheckAutoVariables::errorReturnTempReference(const Token *tok)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::error, "returnTempReference", "Returning reference to temporary");
|
reportError(tok, Severity::error, "returnTempReference", "Reference to temporary returned.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckAutoVariables::errorInvalidDeallocation(const Token *tok)
|
void CheckAutoVariables::errorInvalidDeallocation(const Token *tok)
|
||||||
|
@ -301,8 +302,8 @@ void CheckAutoVariables::errorInvalidDeallocation(const Token *tok)
|
||||||
reportError(tok,
|
reportError(tok,
|
||||||
Severity::error,
|
Severity::error,
|
||||||
"autovarInvalidDeallocation",
|
"autovarInvalidDeallocation",
|
||||||
"Deallocating auto-variable is invalid\n"
|
"Deallocation of an auto-variable results in undefined behaviour.\n"
|
||||||
"Deallocating an auto-variable is invalid. You should only free memory "
|
"Deallocation of an auto-variable results in undefined behaviour. You should only free memory "
|
||||||
"that has been allocated dynamically.");
|
"that has been allocated dynamically.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,5 +342,5 @@ void CheckAutoVariables::returncstr()
|
||||||
|
|
||||||
void CheckAutoVariables::errorReturnTempPointer(const Token *tok)
|
void CheckAutoVariables::errorReturnTempPointer(const Token *tok)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::error, "returnTempPointer", "Returning pointer to temporary");
|
reportError(tok, Severity::error, "returnTempPointer", "Pointer to temporary returned.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,21 +65,21 @@ private:
|
||||||
" int y = x & 4;\n"
|
" int y = x & 4;\n"
|
||||||
" if (y == 3);\n"
|
" if (y == 3);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) Mismatching assignment and comparison, comparison is always false\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) Mismatching assignment and comparison, comparison is always false.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(int x)\n"
|
check("void foo(int x)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int y = x & 4;\n"
|
" int y = x & 4;\n"
|
||||||
" if (y != 3);\n"
|
" if (y != 3);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) Mismatching assignment and comparison, comparison is always true\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) Mismatching assignment and comparison, comparison is always true.\n", errout.str());
|
||||||
|
|
||||||
// |
|
// |
|
||||||
check("void foo(int x) {\n"
|
check("void foo(int x) {\n"
|
||||||
" int y = x | 0x14;\n"
|
" int y = x | 0x14;\n"
|
||||||
" if (y == 0x710);\n"
|
" if (y == 0x710);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) Mismatching assignment and comparison, comparison is always false\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) Mismatching assignment and comparison, comparison is always false.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(int x) {\n"
|
check("void foo(int x) {\n"
|
||||||
" int y = x | 0x14;\n"
|
" int y = x | 0x14;\n"
|
||||||
|
@ -93,19 +93,19 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" if (x & 4 == 3);\n"
|
" if (x & 4 == 3);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X & 0x4) == 0x3' is always false\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X & 0x4) == 0x3' is always false.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(int x)\n"
|
check("void foo(int x)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" if ((x & 4) == 3);\n"
|
" if ((x & 4) == 3);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X & 0x4) == 0x3' is always false\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X & 0x4) == 0x3' is always false.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(int x)\n"
|
check("void foo(int x)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" if (x & 4 != 3);\n"
|
" if (x & 4 != 3);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X & 0x4) != 0x3' is always true\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X & 0x4) != 0x3' is always true.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void multicompare() {
|
void multicompare() {
|
||||||
|
@ -114,14 +114,14 @@ private:
|
||||||
" if (x & 7);\n"
|
" if (x & 7);\n"
|
||||||
" else if (x == 1);\n"
|
" else if (x == 1);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) 'else if' condition matches previous condition at line 3\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) Expression is always false because 'else if' condition matches previous condition at line 3.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(int x)\n"
|
check("void foo(int x)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" if (x & 7);\n"
|
" if (x & 7);\n"
|
||||||
" else if (x & 1);\n"
|
" else if (x & 1);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) 'else if' condition matches previous condition at line 3\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) Expression is always false because 'else if' condition matches previous condition at line 3.\n", errout.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ private:
|
||||||
" int num = 2;\n"
|
" int num = 2;\n"
|
||||||
" *res = #\n"
|
" *res = #\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Assigning address of local auto-variable to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
|
|
||||||
check("void func1(int **res)\n"
|
check("void func1(int **res)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -132,7 +132,7 @@ private:
|
||||||
" int num = 2;\n"
|
" int num = 2;\n"
|
||||||
" *res = #\n"
|
" *res = #\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (error) Assigning address of local auto-variable to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
|
|
||||||
check("class Fred {\n"
|
check("class Fred {\n"
|
||||||
" void func1(int **res);\n"
|
" void func1(int **res);\n"
|
||||||
|
@ -161,7 +161,7 @@ private:
|
||||||
" int x[100];\n"
|
" int x[100];\n"
|
||||||
" *p = x;\n"
|
" *p = x;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Assigning address of local auto-variable to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testautovar4() { // ticket #2928
|
void testautovar4() { // ticket #2928
|
||||||
|
@ -186,7 +186,7 @@ private:
|
||||||
" char a;\n"
|
" char a;\n"
|
||||||
" ab->a = &a;\n"
|
" ab->a = &a;\n"
|
||||||
"}", true);
|
"}", true);
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Assigning address of local auto-variable to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testautovar6() { // ticket #2931
|
void testautovar6() { // ticket #2931
|
||||||
|
@ -202,7 +202,7 @@ private:
|
||||||
" char a[10];\n"
|
" char a[10];\n"
|
||||||
" x->str = a;\n"
|
" x->str = a;\n"
|
||||||
"}", true);
|
"}", true);
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Assigning address of local auto-variable to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testautovar7() { // ticket #3066
|
void testautovar7() { // ticket #3066
|
||||||
|
@ -220,7 +220,7 @@ private:
|
||||||
" int i = 0;\n"
|
" int i = 0;\n"
|
||||||
" p = &i;\n"
|
" p = &i;\n"
|
||||||
"}", false);
|
"}", false);
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Assigning address of local auto-variable to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testautovar9() {
|
void testautovar9() {
|
||||||
|
@ -233,7 +233,7 @@ private:
|
||||||
" p = &p_fp->i;\n"
|
" p = &p_fp->i;\n"
|
||||||
" p = &fp.f->i;\n"
|
" p = &fp.f->i;\n"
|
||||||
"}", false);
|
"}", false);
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (error) Assigning address of local auto-variable to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testautovar_array1() {
|
void testautovar_array1() {
|
||||||
|
@ -242,7 +242,7 @@ private:
|
||||||
" int num=2;"
|
" int num=2;"
|
||||||
" arr[0]=#\n"
|
" arr[0]=#\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Assigning address of local auto-variable to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testautovar_array2() {
|
void testautovar_array2() {
|
||||||
|
@ -254,7 +254,7 @@ private:
|
||||||
" int num=2;"
|
" int num=2;"
|
||||||
" arr[0]=#\n"
|
" arr[0]=#\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (error) Assigning address of local auto-variable to a function parameter.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testautovar_return1() {
|
void testautovar_return1() {
|
||||||
|
@ -263,7 +263,7 @@ private:
|
||||||
" int num=2;"
|
" int num=2;"
|
||||||
" return #"
|
" return #"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Return of the address of an auto-variable\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Address of an auto-variable returned.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testautovar_return2() {
|
void testautovar_return2() {
|
||||||
|
@ -275,7 +275,7 @@ private:
|
||||||
" int num=2;"
|
" int num=2;"
|
||||||
" return #"
|
" return #"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (error) Return of the address of an auto-variable\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (error) Address of an auto-variable returned.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testautovar_return3() {
|
void testautovar_return3() {
|
||||||
|
@ -295,7 +295,7 @@ private:
|
||||||
" char q[] = \"AAAAAAAAAAAA\";\n"
|
" char q[] = \"AAAAAAAAAAAA\";\n"
|
||||||
" return &q[1];\n"
|
" return &q[1];\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Return of the address of an auto-variable\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Address of an auto-variable returned.\n", errout.str());
|
||||||
|
|
||||||
check("char *foo()\n"
|
check("char *foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -327,11 +327,11 @@ private:
|
||||||
" char tmp5[256];\n"
|
" char tmp5[256];\n"
|
||||||
" delete[] tmp5;\n"
|
" delete[] tmp5;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Deallocating auto-variable is invalid\n"
|
ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n"
|
||||||
"[test.cpp:5]: (error) Deallocating auto-variable is invalid\n"
|
"[test.cpp:5]: (error) Deallocation of an auto-variable results in undefined behaviour.\n"
|
||||||
"[test.cpp:7]: (error) Deallocating auto-variable is invalid\n"
|
"[test.cpp:7]: (error) Deallocation of an auto-variable results in undefined behaviour.\n"
|
||||||
"[test.cpp:9]: (error) Deallocating auto-variable is invalid\n"
|
"[test.cpp:9]: (error) Deallocation of an auto-variable results in undefined behaviour.\n"
|
||||||
"[test.cpp:11]: (error) Deallocating auto-variable is invalid\n", errout.str());
|
"[test.cpp:11]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", errout.str());
|
||||||
|
|
||||||
check("void func1() {\n"
|
check("void func1() {\n"
|
||||||
" char* tmp1[256];\n"
|
" char* tmp1[256];\n"
|
||||||
|
@ -374,7 +374,7 @@ private:
|
||||||
" char str[100] = {0};\n"
|
" char str[100] = {0};\n"
|
||||||
" return str;\n"
|
" return str;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Returning pointer to local array variable\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Pointer to local array variable returned.\n", errout.str());
|
||||||
|
|
||||||
check("class Fred {\n"
|
check("class Fred {\n"
|
||||||
" char *foo();\n"
|
" char *foo();\n"
|
||||||
|
@ -384,7 +384,7 @@ private:
|
||||||
" char str[100] = {0};\n"
|
" char str[100] = {0};\n"
|
||||||
" return str;\n"
|
" return str;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (error) Returning pointer to local array variable\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (error) Pointer to local array variable returned.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void returnLocalVariable2() {
|
void returnLocalVariable2() {
|
||||||
|
@ -412,14 +412,14 @@ private:
|
||||||
" std::string s;\n"
|
" std::string s;\n"
|
||||||
" return s;\n"
|
" return s;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Returning reference to auto variable\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Reference to auto variable returned.\n", errout.str());
|
||||||
|
|
||||||
check("std::vector<int> &foo()\n"
|
check("std::vector<int> &foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" std::vector<int> v;\n"
|
" std::vector<int> v;\n"
|
||||||
" return v;\n"
|
" return v;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Returning reference to auto variable\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Reference to auto variable returned.\n", errout.str());
|
||||||
|
|
||||||
check("std::vector<int> &foo()\n"
|
check("std::vector<int> &foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -437,7 +437,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" return hello();\n"
|
" return hello();\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (error) Returning reference to temporary\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (error) Reference to temporary returned.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void returnReference2() {
|
void returnReference2() {
|
||||||
|
@ -449,7 +449,7 @@ private:
|
||||||
" std::string s;\n"
|
" std::string s;\n"
|
||||||
" return s;\n"
|
" return s;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (error) Returning reference to auto variable\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (error) Reference to auto variable returned.\n", errout.str());
|
||||||
|
|
||||||
check("class Fred {\n"
|
check("class Fred {\n"
|
||||||
" std::vector<int> &foo();\n"
|
" std::vector<int> &foo();\n"
|
||||||
|
@ -459,7 +459,7 @@ private:
|
||||||
" std::vector<int> v;\n"
|
" std::vector<int> v;\n"
|
||||||
" return v;\n"
|
" return v;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (error) Returning reference to auto variable\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (error) Reference to auto variable returned.\n", errout.str());
|
||||||
|
|
||||||
check("class Fred {\n"
|
check("class Fred {\n"
|
||||||
" std::vector<int> &foo();\n"
|
" std::vector<int> &foo();\n"
|
||||||
|
@ -482,7 +482,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" return hello();\n"
|
" return hello();\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:10]: (error) Returning reference to temporary\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:10]: (error) Reference to temporary returned.\n", errout.str());
|
||||||
|
|
||||||
check("class Fred {\n"
|
check("class Fred {\n"
|
||||||
" std::string hello();\n"
|
" std::string hello();\n"
|
||||||
|
@ -496,7 +496,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" return hello();\n"
|
" return hello();\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:11]: (error) Returning reference to temporary\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:11]: (error) Reference to temporary returned.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void returnReference3() {
|
void returnReference3() {
|
||||||
|
@ -556,7 +556,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" return hello().c_str();\n"
|
" return hello().c_str();\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (error) Returning pointer to temporary\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (error) Pointer to temporary returned.\n", errout.str());
|
||||||
|
|
||||||
check("class Fred {\n"
|
check("class Fred {\n"
|
||||||
" std::string hello();\n"
|
" std::string hello();\n"
|
||||||
|
@ -570,7 +570,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" return hello().c_str();\n"
|
" return hello().c_str();\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:11]: (error) Returning pointer to temporary\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:11]: (error) Pointer to temporary returned.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -594,14 +594,14 @@ private:
|
||||||
" return &y;\n"
|
" return &y;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Return the address of function parameter 'y'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Address of function parameter 'y' returned.\n", errout.str());
|
||||||
|
|
||||||
check("int ** foo(int * y)\n"
|
check("int ** foo(int * y)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" return &y;\n"
|
" return &y;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Return the address of function parameter 'y'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Address of function parameter 'y' returned.\n", errout.str());
|
||||||
|
|
||||||
check("const int * foo(const int & y)\n"
|
check("const int * foo(const int & y)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue