diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 3fd722ebbe1..217f6c1a606 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -51,6 +51,7 @@ class TestAutoVariables : public TestFixture { } void run() override { + mNewTemplate = true; TEST_CASE(testautovar1); TEST_CASE(testautovar2); TEST_CASE(testautovar3); // ticket #2925 @@ -174,14 +175,14 @@ class TestAutoVariables : public TestFixture { " int num = 2;\n" " *res = #\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); check("void func1(int **res)\n" "{\n" " int num = 2;\n" " res = #\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? [uselessAssignmentPtrArg]\n", errout_str()); check("void func1(int **res)\n" "{\n" @@ -200,7 +201,7 @@ class TestAutoVariables : public TestFixture { " int num = 2;\n" " *res = #\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:5]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); check("class Fred {\n" " void func1(int **res);\n" @@ -210,7 +211,7 @@ class TestAutoVariables : public TestFixture { " int num = 2;\n" " res = #\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:5]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? [uselessAssignmentPtrArg]\n", errout_str()); check("class Fred {\n" " void func1(int **res);\n" @@ -229,7 +230,7 @@ class TestAutoVariables : public TestFixture { " int x[100];\n" " *p = x;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); } void testautovar4() { // ticket #2928 @@ -247,7 +248,7 @@ class TestAutoVariables : public TestFixture { " char a;\n" " ab->a = &a;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (error, inconclusive) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); } void testautovar6() { // ticket #2931 @@ -263,7 +264,7 @@ class TestAutoVariables : public TestFixture { " char a[10];\n" " x->str = a;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (error, inconclusive) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); } void testautovar7() { // ticket #3066 @@ -281,7 +282,7 @@ class TestAutoVariables : public TestFixture { " int i = 0;\n" " p = &i;\n" "}", dinit(CheckOptions, $.inconclusive = false)); - ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); check("void foo(std::string& s) {\n" " s = foo;\n" @@ -297,7 +298,7 @@ class TestAutoVariables : public TestFixture { " FP fp;\n" " p = &fn.i;\n" "}", dinit(CheckOptions, $.inconclusive = false)); - ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:5]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); check("struct FN {int i;};\n" "struct FP {FN* f};\n" @@ -322,22 +323,22 @@ class TestAutoVariables : public TestFixture { check("void foo(char* p) {\n" " p = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? [uselessAssignmentPtrArg]\n", errout_str()); check("void foo(int b) {\n" " b = foo(b);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Assignment of function parameter has no effect outside the function.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (style) Assignment of function parameter has no effect outside the function. [uselessAssignmentArg]\n", errout_str()); check("void foo(int b) {\n" " b += 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Assignment of function parameter has no effect outside the function.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (style) Assignment of function parameter has no effect outside the function. [uselessAssignmentArg]\n", errout_str()); check("void foo(std::string s) {\n" " s = foo(b);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Assignment of function parameter has no effect outside the function.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (style) Assignment of function parameter has no effect outside the function. [uselessAssignmentArg]\n", errout_str()); check("void foo(char* p) {\n" // don't warn for self assignment, there is another warning for this " p = p;\n" @@ -370,13 +371,13 @@ class TestAutoVariables : public TestFixture { check("void foo(Foo* p) {\n" " p = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? [uselessAssignmentPtrArg]\n", errout_str()); check("class Foo {};\n" "void foo(Foo p) {\n" " p = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Assignment of function parameter has no effect outside the function.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (style) Assignment of function parameter has no effect outside the function. [uselessAssignmentArg]\n", errout_str()); check("void foo(Foo p) {\n" " p = 0;\n" @@ -398,12 +399,12 @@ class TestAutoVariables : public TestFixture { check("void foo(int* ptr) {\n" // #4793 " ptr++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? [uselessAssignmentPtrArg]\n", errout_str()); check("void foo(int* ptr) {\n" // #3177 " --ptr;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:7]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? [uselessAssignmentPtrArg]\n", errout_str()); check("void foo(struct S* const x) {\n" // #7839 " ++x->n;\n" @@ -428,7 +429,7 @@ class TestAutoVariables : public TestFixture { " struct A a = bar();\n" " *p = &a.data[0];\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:5]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); check("void f(char **out) {\n" " struct S *p = glob;\n" @@ -447,7 +448,7 @@ class TestAutoVariables : public TestFixture { " s8 p[10];\n" // <- p is array => error " *out = &p[1];\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:3]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); } void testautovar12() { // Ticket #5024, #5050 - Crash on invalid input @@ -507,7 +508,7 @@ class TestAutoVariables : public TestFixture { " int num=2;" " arr[0]=#\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); } void testautovar_array2() { @@ -519,7 +520,7 @@ class TestAutoVariables : public TestFixture { " int num=2;" " arr[0]=#\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:19]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); } void testautovar_array3() { @@ -537,8 +538,8 @@ class TestAutoVariables : public TestFixture { " std::string a = \"abc\";\n" " c[0] = a.data();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n" - "[test.cpp:7]: (error) Address of local auto-variable assigned to a function parameter.\n", + ASSERT_EQUALS("[test.cpp:3:5]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n" + "[test.cpp:7:5]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); check("struct String {\n" @@ -563,7 +564,7 @@ class TestAutoVariables : public TestFixture { " XPoint DropPoint;\n" " ds->location_data = (XtPointer *)&DropPoint;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (error, inconclusive) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); } void testautovar_ptrptr() { // #6596 @@ -571,7 +572,7 @@ class TestAutoVariables : public TestFixture { " char dead_slot;\n" " matches[0] = (char *)&dead_slot;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:3]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); } void testautovar_return1() { @@ -580,7 +581,7 @@ class TestAutoVariables : public TestFixture { " int num=2;" " return #" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3] -> [test.cpp:3]: (error) Returning pointer to local variable 'num' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:26] -> [test.cpp:3:9] -> [test.cpp:3:26]: (error) Returning pointer to local variable 'num' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); } void testautovar_return2() { @@ -592,7 +593,7 @@ class TestAutoVariables : public TestFixture { " int num=2;" " return #" "}"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:6] -> [test.cpp:6]: (error) Returning pointer to local variable 'num' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:26] -> [test.cpp:6:9] -> [test.cpp:6:26]: (error) Returning pointer to local variable 'num' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); } void testautovar_return3() { @@ -647,7 +648,7 @@ class TestAutoVariables : public TestFixture { " if (condition) return;\n" // <- not reassigned => error " pcb->root0 = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:3]: (error, inconclusive) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); check("void foo(cb* pcb) {\n" " int root0;\n" @@ -656,7 +657,7 @@ class TestAutoVariables : public TestFixture { " if (condition)\n" " pcb->root0 = 0;\n" // <- conditional reassign => error "}"); - ASSERT_EQUALS("[test.cpp:3]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:3]: (error, inconclusive) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); check("struct S { int *p; };\n" "void g(struct S* s) {\n" @@ -669,8 +670,8 @@ class TestAutoVariables : public TestFixture { " g(&s);\n" "}"); ASSERT_EQUALS( - "[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n" - "[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", // duplicate + "[test.cpp:4:5]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n" + "[test.cpp:4:5]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", // duplicate errout_str()); } @@ -687,11 +688,11 @@ class TestAutoVariables : public TestFixture { " char tmp5[256];\n" " delete[] tmp5;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n" - "[test.cpp:5]: (error) Deallocation of an auto-variable results in undefined behaviour.\n" - "[test.cpp:7]: (error) Deallocation of an auto-variable results in undefined behaviour.\n" - "[test.cpp:9]: (error) Deallocation of an auto-variable results in undefined behaviour.\n" - "[test.cpp:11]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (error) Deallocation of an auto-variable results in undefined behaviour. [autovarInvalidDeallocation]\n" + "[test.cpp:5:12]: (error) Deallocation of an auto-variable results in undefined behaviour. [autovarInvalidDeallocation]\n" + "[test.cpp:7:12]: (error) Deallocation of an auto-variable results in undefined behaviour. [autovarInvalidDeallocation]\n" + "[test.cpp:9:15]: (error) Deallocation of an auto-variable results in undefined behaviour. [autovarInvalidDeallocation]\n" + "[test.cpp:11:14]: (error) Deallocation of an auto-variable results in undefined behaviour. [autovarInvalidDeallocation]\n", errout_str()); check("void func1(char * ptr) {\n" " free(ptr);\n" @@ -710,14 +711,14 @@ class TestAutoVariables : public TestFixture { " char *p = tmp1;\n" " free(p);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Deallocation of a static variable (tmp1) results in undefined behaviour.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (error) Deallocation of a static variable (tmp1) results in undefined behaviour. [autovarInvalidDeallocation]\n", errout_str()); check("char tmp1[256];\n" "void func1() {\n" " char *p; if (x) p = tmp1;\n" " free(p);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Deallocation of a global variable (tmp1) results in undefined behaviour.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (error) Deallocation of a global variable (tmp1) results in undefined behaviour. [autovarInvalidDeallocation]\n", errout_str()); check("void f()\n" "{\n" @@ -736,13 +737,13 @@ class TestAutoVariables : public TestFixture { " free(&p);\n" " return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (error) Deallocation of an auto-variable results in undefined behaviour. [autovarInvalidDeallocation]\n", errout_str()); check("int main() {\n" " int i;\n" " free(&i);\n" " return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (error) Deallocation of an auto-variable results in undefined behaviour. [autovarInvalidDeallocation]\n", errout_str()); // #5732 check("int main() {\n" @@ -755,13 +756,13 @@ class TestAutoVariables : public TestFixture { " long *pKoeff[256];\n" " delete[] pKoeff;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (error) Deallocation of an auto-variable results in undefined behaviour. [autovarInvalidDeallocation]\n", errout_str()); check("int main() {\n" " long *pKoeff[256];\n" " free (pKoeff);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (error) Deallocation of an auto-variable results in undefined behaviour. [autovarInvalidDeallocation]\n", errout_str()); check("void foo() {\n" " const intPtr& intref = Getter();\n" @@ -835,7 +836,7 @@ class TestAutoVariables : public TestFixture { " S* p = &s;\n" " free(p);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (error) Deallocation of an auto-variable (s) results in undefined behaviour.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (error) Deallocation of an auto-variable (s) results in undefined behaviour. [autovarInvalidDeallocation]\n", errout_str()); check("void f(bool b, int* q) {\n" " int i;\n" @@ -901,11 +902,11 @@ class TestAutoVariables : public TestFixture { " p = \"abc\";\n" " free(p);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of a string literal results in undefined behaviour.\n" - "[test.cpp:4]: (error) Deallocation of a string literal results in undefined behaviour.\n" - "[test.cpp:5]: (error) Deallocation of a pointer pointing to a string literal (\"a\") results in undefined behaviour.\n" - "[test.cpp:6]: (error) Deallocation of a pointer pointing to a string literal (\"a\") results in undefined behaviour.\n" - "[test.cpp:9]: (error) Deallocation of a pointer pointing to a string literal (\"abc\") results in undefined behaviour.\n", + ASSERT_EQUALS("[test.cpp:3:10]: (error) Deallocation of a string literal results in undefined behaviour. [autovarInvalidDeallocation]\n" + "[test.cpp:4:12]: (error) Deallocation of a string literal results in undefined behaviour. [autovarInvalidDeallocation]\n" + "[test.cpp:5:10]: (error) Deallocation of a pointer pointing to a string literal (\"a\") results in undefined behaviour. [autovarInvalidDeallocation]\n" + "[test.cpp:6:12]: (error) Deallocation of a pointer pointing to a string literal (\"a\") results in undefined behaviour. [autovarInvalidDeallocation]\n" + "[test.cpp:9:10]: (error) Deallocation of a pointer pointing to a string literal (\"abc\") results in undefined behaviour. [autovarInvalidDeallocation]\n", errout_str()); check("void f() {\n" @@ -950,7 +951,7 @@ class TestAutoVariables : public TestFixture { " int x[10];\n" " p = x;\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Non-local variable 'p' will use pointer to local variable 'x'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7] -> [test.cpp:3:7] -> [test.cpp:4:3]: (error) Non-local variable 'p' will use pointer to local variable 'x'. [danglingLifetime]\n", errout_str()); check("int *p;\n" "void f() {\n" @@ -967,7 +968,7 @@ class TestAutoVariables : public TestFixture { " int x;\n" " p = &x;\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Non-local variable 'p' will use pointer to local variable 'x'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7] -> [test.cpp:3:7] -> [test.cpp:4:3]: (error) Non-local variable 'p' will use pointer to local variable 'x'. [danglingLifetime]\n", errout_str()); check("int *p;\n" "void f() {\n" @@ -986,7 +987,7 @@ class TestAutoVariables : public TestFixture { " }\n" " int *ptr;\n" "};"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Non-local variable 'ptr' will use pointer to local variable 'x'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11] -> [test.cpp:3:9] -> [test.cpp:4:5]: (error) Non-local variable 'ptr' will use pointer to local variable 'x'. [danglingLifetime]\n", errout_str()); check("struct A {\n" " void f() {\n" @@ -1021,7 +1022,7 @@ class TestAutoVariables : public TestFixture { " return str;\n" "}"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Returning pointer to local variable 'str' that will be invalid when returning.\n", + "[test.cpp:4:12] -> [test.cpp:3:10] -> [test.cpp:4:12]: (error) Returning pointer to local variable 'str' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("char *foo()\n" // use ValueFlow @@ -1031,7 +1032,7 @@ class TestAutoVariables : public TestFixture { " return p;\n" "}"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:3] -> [test.cpp:5]: (error) Returning pointer to local variable 'str' that will be invalid when returning.\n", + "[test.cpp:4:15] -> [test.cpp:3:10] -> [test.cpp:5:12]: (error) Returning pointer to local variable 'str' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("class Fred {\n" @@ -1043,7 +1044,7 @@ class TestAutoVariables : public TestFixture { " return str;\n" "}"); ASSERT_EQUALS( - "[test.cpp:7] -> [test.cpp:6] -> [test.cpp:7]: (error) Returning pointer to local variable 'str' that will be invalid when returning.\n", + "[test.cpp:7:12] -> [test.cpp:6:10] -> [test.cpp:7:12]: (error) Returning pointer to local variable 'str' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("char * format_reg(char *outbuffer_start) {\n" @@ -1083,7 +1084,7 @@ class TestAutoVariables : public TestFixture { " char q[] = \"AAAAAAAAAAAA\";\n" " return &q[1];\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning pointer to local variable 'q' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12] -> [test.cpp:2:10] -> [test.cpp:3:12]: (error) Returning pointer to local variable 'q' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("char *foo()\n" "{\n" @@ -1099,7 +1100,7 @@ class TestAutoVariables : public TestFixture { "p = &q[1];\n" "return p;\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Returning pointer to local variable 'q' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:5] -> [test.cpp:3:6] -> [test.cpp:6:8]: (error) Returning pointer to local variable 'q' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); } void returnLocalVariable4() { // x+y @@ -1108,7 +1109,7 @@ class TestAutoVariables : public TestFixture { " return x+5;\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n", + "[test.cpp:3:12] -> [test.cpp:2:10] -> [test.cpp:3:13]: (error) Returning pointer to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("char *foo(int y) {\n" @@ -1116,7 +1117,7 @@ class TestAutoVariables : public TestFixture { " return (x+8)-y;\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n", + "[test.cpp:3:13] -> [test.cpp:2:10] -> [test.cpp:3:17]: (error) Returning pointer to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); } @@ -1126,7 +1127,7 @@ class TestAutoVariables : public TestFixture { " return (char *)x;\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n", + "[test.cpp:3:20] -> [test.cpp:2:9] -> [test.cpp:3:12]: (error) Returning pointer to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); } @@ -1136,7 +1137,7 @@ class TestAutoVariables : public TestFixture { " int p = &x;\n" " return p;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'x' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13] -> [test.cpp:2:9] -> [test.cpp:4:12]: (error) Returning object that points to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); } void returnReference1() { @@ -1146,21 +1147,21 @@ class TestAutoVariables : public TestFixture { " int& x = s;\n" " return x;\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5]: (error) Reference to local variable returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12] -> [test.cpp:5:12]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("std::string &foo()\n" "{\n" " std::string s;\n" " return s;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Reference to local variable returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("std::vector &foo()\n" "{\n" " std::vector v;\n" " return v;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Reference to local variable returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("std::vector &foo()\n" "{\n" @@ -1185,7 +1186,7 @@ class TestAutoVariables : public TestFixture { "{\n" " return hello();\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:17]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); // make sure scope is used in function lookup check("class Fred {\n" @@ -1205,7 +1206,7 @@ class TestAutoVariables : public TestFixture { "std::string &f() {\n" " return hello();\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:17]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("std::string hello() {\n" " return \"foo\";\n" @@ -1214,7 +1215,7 @@ class TestAutoVariables : public TestFixture { "std::string &f() {\n" " return hello().substr(1);\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:26]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("class Foo;\n" "Foo hello() {\n" @@ -1224,7 +1225,7 @@ class TestAutoVariables : public TestFixture { "Foo& f() {\n" " return hello();\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:17]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); // make sure function overloads are handled properly check("class Foo;\n" @@ -1260,7 +1261,7 @@ class TestAutoVariables : public TestFixture { " std::string s;\n" " return s;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Reference to local variable returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:12]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("class Fred {\n" " std::vector &foo();\n" @@ -1270,7 +1271,7 @@ class TestAutoVariables : public TestFixture { " std::vector v;\n" " return v;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Reference to local variable returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:12]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("class Fred {\n" " std::vector &foo();\n" @@ -1293,7 +1294,7 @@ class TestAutoVariables : public TestFixture { "{\n" " return hello();\n" "}"); - ASSERT_EQUALS("[test.cpp:10]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:17]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("class Fred {\n" " std::string hello();\n" @@ -1307,7 +1308,7 @@ class TestAutoVariables : public TestFixture { "{\n" " return hello();\n" "}"); - ASSERT_EQUALS("[test.cpp:11]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:11:17]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("class Bar;\n" "Bar foo() {\n" @@ -1316,7 +1317,7 @@ class TestAutoVariables : public TestFixture { "Bar& bar() {\n" " return foo();\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:15]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("std::map foo() {\n" " return something;\n" @@ -1324,7 +1325,7 @@ class TestAutoVariables : public TestFixture { "std::map& bar() {\n" " return foo();\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:15]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("Bar foo() {\n" " return something;\n" @@ -1424,7 +1425,7 @@ class TestAutoVariables : public TestFixture { " A a;\n" " return a.f();\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:15]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("class A { int& f() const; };\n" "int& g() {\n" @@ -1439,7 +1440,7 @@ class TestAutoVariables : public TestFixture { "int& g() {\n" " return A::f();\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("class A { static int& f(); };\n" "int& g() {\n" @@ -1604,7 +1605,7 @@ class TestAutoVariables : public TestFixture { " std::unique_ptr p = std::make_unique(1);\n" " return *p;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Reference to local variable returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("void g(const std::unique_ptr&);\n" "int& f() {\n" @@ -1612,7 +1613,7 @@ class TestAutoVariables : public TestFixture { " g(p);\n" " return *p;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (error) Reference to local variable returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("void g(std::shared_ptr);\n" "int& f() {\n" @@ -1632,14 +1633,14 @@ class TestAutoVariables : public TestFixture { "int& f() {\n" " return *g();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("struct A { int x; };\n" "int& f() {\n" " std::unique_ptr p = std::make_unique();\n" " return p->x;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Reference to local variable returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); } void returnReference23() { @@ -1658,7 +1659,7 @@ class TestAutoVariables : public TestFixture { "const A& a() {\n" " return A();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:13]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); } void returnReference25() @@ -1680,7 +1681,7 @@ class TestAutoVariables : public TestFixture { " int& s{ x };\n" " return s;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Reference to local variable returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:4:12]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); } void returnReference27() @@ -1715,7 +1716,7 @@ class TestAutoVariables : public TestFixture { " return f(x);\n" "}"); ASSERT_EQUALS( - "[test.cpp:1] -> [test.cpp:2] -> [test.cpp:6] -> [test.cpp:6]: (error) Reference to local variable returned.\n", + "[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:6:12] -> [test.cpp:6:13]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("int& f(int& a) {\n" @@ -1726,7 +1727,7 @@ class TestAutoVariables : public TestFixture { " return &f(x);\n" "}"); ASSERT_EQUALS( - "[test.cpp:1] -> [test.cpp:2] -> [test.cpp:6] -> [test.cpp:6] -> [test.cpp:5] -> [test.cpp:6]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n", + "[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:6:13] -> [test.cpp:6:12] -> [test.cpp:5:9] -> [test.cpp:6:12]: (error) Returning pointer to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("int* f(int * x) {\n" @@ -1735,7 +1736,7 @@ class TestAutoVariables : public TestFixture { "int * g(int x) {\n" " return f(&x);\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:5] -> [test.cpp:4] -> [test.cpp:5]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:14] -> [test.cpp:5:14] -> [test.cpp:4:13] -> [test.cpp:5:13]: (error) Returning pointer to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("int* f(int * x) {\n" " x = nullptr;\n" @@ -1753,7 +1754,7 @@ class TestAutoVariables : public TestFixture { " int x = 0;\n" " return f(x);\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:13]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("int& f(int a) {\n" " return a;\n" @@ -1762,7 +1763,7 @@ class TestAutoVariables : public TestFixture { " int x = 0;\n" " return f(x);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Reference to local variable returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("int f(int a) {\n" " return a;\n" @@ -1771,7 +1772,7 @@ class TestAutoVariables : public TestFixture { " int x = 0;\n" " return f(x);\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:13]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("template\n" "int& f(int& x, T y) {\n" @@ -1786,31 +1787,31 @@ class TestAutoVariables : public TestFixture { " std::vector x;\n" " return x[0];\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Reference to local variable returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("auto& f() {\n" " std::vector x;\n" " return x.front();\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (error) Reference to local variable returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14] -> [test.cpp:3:19]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("std::vector g();\n" "auto& f() {\n" " return g().front();\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16] -> [test.cpp:3:21]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("auto& f() {\n" " return std::vector{1}.front();\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:32] -> [test.cpp:2:37]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("struct A { int foo; };\n" "int& f(std::vector v) {\n" " auto it = v.begin();\n" " return it->foo;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Reference to local variable returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:22] -> [test.cpp:4:14]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("template \n" "const V& get_default(const T& t, const K& k, const V& v) {\n" @@ -1823,7 +1824,7 @@ class TestAutoVariables : public TestFixture { " return get_default(m, k, x);\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:4] -> [test.cpp:9] -> [test.cpp:9]: (error, inconclusive) Reference to local variable returned.\n", + "[test.cpp:2:56] -> [test.cpp:4:31] -> [test.cpp:9:12] -> [test.cpp:9:23]: (error, inconclusive) Reference to local variable returned. [returnReference]\n", errout_str()); check("template \n" @@ -1836,7 +1837,7 @@ class TestAutoVariables : public TestFixture { " return get_default(m, k, 0);\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:4] -> [test.cpp:8] -> [test.cpp:8]: (error, inconclusive) Reference to temporary returned.\n", + "[test.cpp:2:56] -> [test.cpp:4:31] -> [test.cpp:8:12] -> [test.cpp:8:23]: (error, inconclusive) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("struct A { int foo; };\n" @@ -1858,7 +1859,7 @@ class TestAutoVariables : public TestFixture { check("const std::string &a() {\n" " return \"foo\";\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("const std::string a() {\n" " return \"foo\";\n" @@ -1870,26 +1871,26 @@ class TestAutoVariables : public TestFixture { " return f(\"foo\");\n" "}"); ASSERT_EQUALS( - "[test.cpp:1] -> [test.cpp:1] -> [test.cpp:3] -> [test.cpp:3]: (error) Reference to temporary returned.\n", + "[test.cpp:1:42] -> [test.cpp:1:53] -> [test.cpp:3:12] -> [test.cpp:3:13]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("const char * f(const char * x) { return x; }\n" "const std::string &a() {\n" " return f(\"foo\");\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); } void returnReferenceCalculation() { check("const std::string &a(const std::string& str) {\n" " return \"foo\" + str;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("int& operator<<(int out, int path) {\n" " return out << path;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("std::ostream& operator<<(std::ostream& out, const std::string& path) {\n" " return out << path;\n" @@ -1909,7 +1910,7 @@ class TestAutoVariables : public TestFixture { check("int& a(int b) {\n" " return 2*(b+1);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("const std::string &a(const std::string& str) {\n" " return str;\n" @@ -1988,7 +1989,7 @@ class TestAutoVariables : public TestFixture { " const int& x = h();\n" " return [&] { return x; };\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5] -> [test.cpp:4] -> [test.cpp:5]: (error) Returning lambda that captures local variable 'x' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:18] -> [test.cpp:5:25] -> [test.cpp:4:16] -> [test.cpp:5:12]: (error) Returning lambda that captures local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("void g(int*);\n" "int h();\n" @@ -1996,7 +1997,7 @@ class TestAutoVariables : public TestFixture { " const int& x = h();\n" " return &x;\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5] -> [test.cpp:4] -> [test.cpp:5]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:18] -> [test.cpp:5:12] -> [test.cpp:4:16] -> [test.cpp:5:12]: (error) Returning pointer to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("void g(int*);\n" "int h();\n" @@ -2005,8 +2006,8 @@ class TestAutoVariables : public TestFixture { " g(&x);\n" "}"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:5] -> [test.cpp:4] -> [test.cpp:5]: (error) Using pointer that is a temporary.\n" - "[test.cpp:4] -> [test.cpp:5]: (error) Using reference to dangling temporary.\n", + "[test.cpp:4:12] -> [test.cpp:5:7] -> [test.cpp:4:15] -> [test.cpp:5:7]: (error) Using pointer that is a temporary. [danglingTemporaryLifetime]\n" + "[test.cpp:4:12] -> [test.cpp:5:8]: (error) Using reference to dangling temporary. [danglingTempReference]\n", errout_str()); check("void g(int*);\n" @@ -2033,7 +2034,7 @@ class TestAutoVariables : public TestFixture { " static int &r = k;\n" " return r;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (error) Non-local reference variable 'r' to local variable 'k'\n", + ASSERT_EQUALS("[test.cpp:3:19] -> [test.cpp:3:17]: (error) Non-local reference variable 'r' to local variable 'k' [danglingReference]\n", errout_str()); check("int &f( int & k )\n" @@ -2052,7 +2053,7 @@ class TestAutoVariables : public TestFixture { " const auto& str_cref2 = g(std::string(\"hello\"));\n" " std::cout << str_cref2 << std::endl;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:1] -> [test.cpp:2] -> [test.cpp:5] -> [test.cpp:6]: (error) Using reference to dangling temporary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:27] -> [test.cpp:1:49] -> [test.cpp:2:12] -> [test.cpp:5:29] -> [test.cpp:6:18]: (error) Using reference to dangling temporary. [danglingTempReference]\n", errout_str()); // Lifetime extended check("std::string g(const std::string& str_cref) {\n" @@ -2097,7 +2098,7 @@ class TestAutoVariables : public TestFixture { " v += 1;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:6] -> [test.cpp:2] -> [test.cpp:6] -> [test.cpp:7]: (error) Using reference to dangling temporary.\n", + "[test.cpp:6:12] -> [test.cpp:2:25] -> [test.cpp:6:19] -> [test.cpp:7:5]: (error) Using reference to dangling temporary. [danglingTempReference]\n", errout_str()); check("struct A {\n" @@ -2121,7 +2122,7 @@ class TestAutoVariables : public TestFixture { " return i;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:7] -> [test.cpp:2] -> [test.cpp:7] -> [test.cpp:8]: (error) Using reference to dangling temporary.\n", + "[test.cpp:7:18] -> [test.cpp:2:35] -> [test.cpp:7:25] -> [test.cpp:8:12]: (error) Using reference to dangling temporary. [danglingTempReference]\n", errout_str()); check("struct S1 {\n" @@ -2139,7 +2140,7 @@ class TestAutoVariables : public TestFixture { " return c.s.val;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:11] -> [test.cpp:2] -> [test.cpp:11] -> [test.cpp:12]: (error) Using reference to dangling temporary.\n", + "[test.cpp:11:13] -> [test.cpp:2:34] -> [test.cpp:11:23] -> [test.cpp:12:5]: (error) Using reference to dangling temporary. [danglingTempReference]\n", errout_str()); check("struct C {\n" @@ -2187,7 +2188,7 @@ class TestAutoVariables : public TestFixture { " const S& s = *g();\n" " (void)s.i;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:9]: (error) Using reference to dangling temporary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:16] -> [test.cpp:9:11]: (error) Using reference to dangling temporary. [danglingTempReference]\n", errout_str()); check("std::string f() {\n" // #12173 " std::string s;\n" @@ -2219,14 +2220,14 @@ class TestAutoVariables : public TestFixture { " return &y;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning pointer to local variable 'y' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:1:14] -> [test.cpp:3:10]: (error) Returning pointer to local variable 'y' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("int ** foo(int * y)\n" "{\n" " return &y;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning pointer to local variable 'y' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:1:18] -> [test.cpp:3:10]: (error) Returning pointer to local variable 'y' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("const int * foo(const int & y)\n" "{\n" @@ -2260,7 +2261,7 @@ class TestAutoVariables : public TestFixture { " return const_tree_iterator(foo);\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:31]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); } void variableIsUsedInScope() { @@ -2279,30 +2280,30 @@ class TestAutoVariables : public TestFixture { " auto l = [&](){ return a; };\n" " return l;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:28] -> [test.cpp:2:9] -> [test.cpp:4:12]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f() {\n" " int a = 1;\n" " return [&](){ return a; };\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:26] -> [test.cpp:2:9] -> [test.cpp:3:12]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f(int a) {\n" " return [&](){ return a; };\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:1] -> [test.cpp:2]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:26] -> [test.cpp:1:12] -> [test.cpp:2:12]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f(int a) {\n" " auto p = &a;\n" " return [=](){ return p; };\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14] -> [test.cpp:3:26] -> [test.cpp:1:12] -> [test.cpp:3:12]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto g(int& a) {\n" " int p = a;\n" " return [&](){ return p; };\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'p' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:26] -> [test.cpp:2:9] -> [test.cpp:3:12]: (error) Returning lambda that captures local variable 'p' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f() {\n" " return [=](){\n" @@ -2310,7 +2311,7 @@ class TestAutoVariables : public TestFixture { " return [&](){ return a; };\n" " };\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:30] -> [test.cpp:3:13] -> [test.cpp:4:16]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f(int b) {\n" " return [=](int a){\n" @@ -2318,7 +2319,7 @@ class TestAutoVariables : public TestFixture { " return [&](){ return a; };\n" " };\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:30] -> [test.cpp:2:20] -> [test.cpp:4:16]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto g(int& a) {\n" " return [&](){ return a; };\n" @@ -2355,7 +2356,7 @@ class TestAutoVariables : public TestFixture { " int i = 0;\n" " return [&i] {};\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'i' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14] -> [test.cpp:2:9] -> [test.cpp:3:12]: (error) Returning lambda that captures local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f() {\n" " int i = 0;\n" @@ -2367,14 +2368,14 @@ class TestAutoVariables : public TestFixture { " int i = 0;\n" " return [=, &i] {};\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'i' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17] -> [test.cpp:2:9] -> [test.cpp:3:12]: (error) Returning lambda that captures local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f() {\n" " int i = 0;\n" " int j = 0;\n" " return [=, &i] { return j; };\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'i' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:17] -> [test.cpp:2:9] -> [test.cpp:4:12]: (error) Returning lambda that captures local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f() {\n" " int i = 0;\n" @@ -2387,7 +2388,7 @@ class TestAutoVariables : public TestFixture { " int j = 0;\n" " return [&, i] { return j; };\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'j' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:28] -> [test.cpp:3:9] -> [test.cpp:4:12]: (error) Returning lambda that captures local variable 'j' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f(int& i) {\n" " int j = 0;\n" @@ -2429,14 +2430,14 @@ class TestAutoVariables : public TestFixture { " auto it = x.begin();\n" " return it;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning iterator to local container 'x' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:22] -> [test.cpp:2:22] -> [test.cpp:4:12]: (error) Returning iterator to local container 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f() {\n" " std::vector x;\n" " auto it = std::begin(x);\n" " return it;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning iterator to local container 'x' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:25] -> [test.cpp:2:22] -> [test.cpp:4:12]: (error) Returning iterator to local container 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("int* f() {\n" " std::vector x;\n" @@ -2444,7 +2445,7 @@ class TestAutoVariables : public TestFixture { " return p;\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n", + "[test.cpp:3:20] -> [test.cpp:2:22] -> [test.cpp:4:12]: (error) Returning pointer to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f() {\n" @@ -2453,7 +2454,7 @@ class TestAutoVariables : public TestFixture { " return p;\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n", + "[test.cpp:3:14] -> [test.cpp:2:22] -> [test.cpp:4:12]: (error) Returning pointer to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct A { int foo; };\n" @@ -2462,14 +2463,14 @@ class TestAutoVariables : public TestFixture { " return &it->foo;\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning pointer to local variable 'v' that will be invalid when returning.\n", + "[test.cpp:3:22] -> [test.cpp:4:12] -> [test.cpp:2:23] -> [test.cpp:4:12]: (error) Returning pointer to local variable 'v' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("std::vector::iterator f(std::vector x) {\n" " auto it = x.begin();\n" " return it;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning iterator to local container 'x' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:22] -> [test.cpp:1:47] -> [test.cpp:3:12]: (error) Returning iterator to local container 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f() {\n" " std::vector x;\n" @@ -2477,7 +2478,7 @@ class TestAutoVariables : public TestFixture { " return std::next(it);\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning iterator to local container 'x' that will be invalid when returning.\n", + "[test.cpp:3:22] -> [test.cpp:2:22] -> [test.cpp:4:21]: (error) Returning iterator to local container 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f() {\n" @@ -2486,7 +2487,7 @@ class TestAutoVariables : public TestFixture { " return it + 1;\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning iterator to local container 'x' that will be invalid when returning.\n", + "[test.cpp:3:22] -> [test.cpp:2:22] -> [test.cpp:4:15]: (error) Returning iterator to local container 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f() {\n" @@ -2495,7 +2496,7 @@ class TestAutoVariables : public TestFixture { " return std::next(it + 1);\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'x' that will be invalid when returning.\n", + "[test.cpp:3:22] -> [test.cpp:4:25] -> [test.cpp:2:22] -> [test.cpp:4:21]: (error) Returning object that points to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("std::vector f() {\n" @@ -2505,7 +2506,7 @@ class TestAutoVariables : public TestFixture { " return v;\n" "}"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:4] -> [test.cpp:2] -> [test.cpp:5]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", + "[test.cpp:4:17] -> [test.cpp:4:17] -> [test.cpp:2:9] -> [test.cpp:5:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("std::vector f() {\n" @@ -2517,7 +2518,7 @@ class TestAutoVariables : public TestFixture { " return r;\n" "}"); ASSERT_EQUALS( - "[test.cpp:5] -> [test.cpp:5] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:7]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", + "[test.cpp:5:17] -> [test.cpp:5:17] -> [test.cpp:5:5] -> [test.cpp:3:9] -> [test.cpp:7:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct A {\n" @@ -2528,7 +2529,7 @@ class TestAutoVariables : public TestFixture { " }\n" "};"); ASSERT_EQUALS( - "[test.cpp:5] -> [test.cpp:5] -> [test.cpp:4] -> [test.cpp:5]: (error) Non-local variable 'v' will use object that points to local variable 'i'.\n", + "[test.cpp:5:21] -> [test.cpp:5:21] -> [test.cpp:4:13] -> [test.cpp:5:9]: (error) Non-local variable 'v' will use object that points to local variable 'i'. [danglingLifetime]\n", errout_str()); check("struct A {\n" @@ -2540,7 +2541,7 @@ class TestAutoVariables : public TestFixture { " }\n" "};"); ASSERT_EQUALS( - "[test.cpp:5] -> [test.cpp:6] -> [test.cpp:4] -> [test.cpp:6]: (error) Non-local variable 'v' will use object that points to local variable 'i'.\n", + "[test.cpp:5:19] -> [test.cpp:6:21] -> [test.cpp:4:13] -> [test.cpp:6:9]: (error) Non-local variable 'v' will use object that points to local variable 'i'. [danglingLifetime]\n", errout_str()); check("struct A {\n" @@ -2553,8 +2554,8 @@ class TestAutoVariables : public TestFixture { " }\n" "};"); ASSERT_EQUALS( - "[test.cpp:6] -> [test.cpp:6] -> [test.cpp:6] -> [test.cpp:4] -> [test.cpp:7]: (error) Non-local variable 'm' will use object that points to local variable 'x'.\n" - "[test.cpp:6] -> [test.cpp:6] -> [test.cpp:6] -> [test.cpp:4] -> [test.cpp:7]: (error) Non-local variable 'm' will use object that points to local variable 'x'.\n", // duplicate + "[test.cpp:6:21] -> [test.cpp:6:21] -> [test.cpp:6:9] -> [test.cpp:4:13] -> [test.cpp:7:9]: (error) Non-local variable 'm' will use object that points to local variable 'x'. [danglingLifetime]\n" + "[test.cpp:6:21] -> [test.cpp:6:21] -> [test.cpp:6:9] -> [test.cpp:4:13] -> [test.cpp:7:18]: (error) Non-local variable 'm' will use object that points to local variable 'x'. [danglingLifetime]\n", // duplicate errout_str()); check("std::vector::iterator f(std::vector v) {\n" @@ -2564,7 +2565,7 @@ class TestAutoVariables : public TestFixture { " return {};\n" "}"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning iterator to local container 'v' that will be invalid when returning.\n", + "[test.cpp:2:26] -> [test.cpp:1:47] -> [test.cpp:3:16]: (error) Returning iterator to local container 'v' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("const char * f() {\n" @@ -2572,7 +2573,7 @@ class TestAutoVariables : public TestFixture { " return ba.c_str();\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning pointer to local variable 'ba' that will be invalid when returning.\n", + "[test.cpp:3:19] -> [test.cpp:2:16] -> [test.cpp:3:19]: (error) Returning pointer to local variable 'ba' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("template \n" @@ -2586,14 +2587,14 @@ class TestAutoVariables : public TestFixture { " return get_default(m, k, &x);\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:9] -> [test.cpp:9] -> [test.cpp:8] -> [test.cpp:9]: (error, inconclusive) Returning pointer to local variable 'x' that will be invalid when returning.\n", + "[test.cpp:9:30] -> [test.cpp:9:30] -> [test.cpp:8:10] -> [test.cpp:9:23]: (error, inconclusive) Returning pointer to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("std::vector g();\n" "auto f() {\n" " return g().begin();\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (error) Returning iterator that will be invalid when returning.\n", + ASSERT_EQUALS("[test.cpp:3:21] -> [test.cpp:3:21]: (error) Returning iterator that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("std::vector g();\n" @@ -2601,15 +2602,15 @@ class TestAutoVariables : public TestFixture { " auto it = g().begin();\n" " return it;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3] -> [test.cpp:4]: (error) Using iterator that is a temporary.\n" - "[test.cpp:3] -> [test.cpp:4]: (error) Returning iterator that will be invalid when returning.\n", + ASSERT_EQUALS("[test.cpp:3:24] -> [test.cpp:3:16] -> [test.cpp:4:5]: (error) Using iterator that is a temporary. [danglingTemporaryLifetime]\n" + "[test.cpp:3:24] -> [test.cpp:4:12]: (error) Returning iterator that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("std::vector g();\n" "int& f() {\n" " return *g().begin();\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:22] -> [test.cpp:3:12]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("struct A {\n" " std::vector v;\n" @@ -2739,7 +2740,7 @@ class TestAutoVariables : public TestFixture { " char a = 0;\n" " return std::vector{&a};\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'a' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:31] -> [test.cpp:3:31] -> [test.cpp:2:10] -> [test.cpp:3:30]: (error) Returning object that points to local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("std::vector* g();\n" "int& f() {\n" @@ -2766,7 +2767,7 @@ class TestAutoVariables : public TestFixture { " }\n" "};\n"); ASSERT_EQUALS( - "[test.cpp:8] -> [test.cpp:8] -> [test.cpp:4] -> [test.cpp:7] -> [test.cpp:4]: (error) Non-local variable 'v' will use object that points to local variable 'i'.\n", + "[test.cpp:8:13] -> [test.cpp:8:13] -> [test.cpp:4:21] -> [test.cpp:7:13] -> [test.cpp:4:9]: (error) Non-local variable 'v' will use object that points to local variable 'i'. [danglingLifetime]\n", errout_str()); check("struct A {\n" @@ -2872,7 +2873,7 @@ class TestAutoVariables : public TestFixture { " std::vector::iterator it = x.begin();\n" " return it;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning iterator to local container 'x' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:44] -> [test.cpp:2:22] -> [test.cpp:4:12]: (error) Returning iterator to local container 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); } void danglingLifetimeContainerView() @@ -2882,7 +2883,7 @@ class TestAutoVariables : public TestFixture { " return s;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 's' that will be invalid when returning.\n", + "[test.cpp:3:12] -> [test.cpp:2:17] -> [test.cpp:3:12]: (error) Returning object that points to local variable 's' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("std::string_view f() {\n" @@ -2891,7 +2892,7 @@ class TestAutoVariables : public TestFixture { " return sv;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 's' that will be invalid when returning.\n", + "[test.cpp:3:27] -> [test.cpp:2:17] -> [test.cpp:4:12]: (error) Returning object that points to local variable 's' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("std::string_view f() {\n" @@ -2899,7 +2900,7 @@ class TestAutoVariables : public TestFixture { " return std::string_view{s};\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 's' that will be invalid when returning.\n", + "[test.cpp:3:29] -> [test.cpp:2:17] -> [test.cpp:3:28]: (error) Returning object that points to local variable 's' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("std::string_view f(std::string_view s) {\n" @@ -2910,7 +2911,7 @@ class TestAutoVariables : public TestFixture { " return f(s);\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:6] -> [test.cpp:6] -> [test.cpp:5] -> [test.cpp:6]: (error) Returning object that points to local variable 's' that will be invalid when returning.\n", + "[test.cpp:6:14] -> [test.cpp:6:14] -> [test.cpp:5:17] -> [test.cpp:6:13]: (error) Returning object that points to local variable 's' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("const char * f() {\n" @@ -2919,7 +2920,7 @@ class TestAutoVariables : public TestFixture { " return sv.begin();\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning iterator to local container 's' that will be invalid when returning.\n", + "[test.cpp:4:20] -> [test.cpp:2:17] -> [test.cpp:4:20]: (error) Returning iterator to local container 's' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("const char * f() {\n" @@ -2927,7 +2928,7 @@ class TestAutoVariables : public TestFixture { " return std::string_view{s}.begin();\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning iterator to local container 's' that will be invalid when returning.\n", + "[test.cpp:3:37] -> [test.cpp:2:17] -> [test.cpp:3:37]: (error) Returning iterator to local container 's' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("const char * f() {\n" @@ -2935,7 +2936,7 @@ class TestAutoVariables : public TestFixture { " return std::string_view(s).begin();\n" "}\n"); TODO_ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning iterator to local container 's' that will be invalid when returning.\n", + "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning iterator to local container 's' that will be invalid when returning. [returnDanglingLifetime]\n", "", errout_str()); @@ -2949,14 +2950,14 @@ class TestAutoVariables : public TestFixture { " return sv.begin();\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning iterator to local container 's' that will be invalid when returning.\n", + "[test.cpp:3:20] -> [test.cpp:1:28] -> [test.cpp:3:20]: (error) Returning iterator to local container 's' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("std::string_view f(std::string s) {\n" " return s;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:1] -> [test.cpp:2]: (error) Returning object that points to local variable 's' that will be invalid when returning.\n", + "[test.cpp:2:12] -> [test.cpp:1:32] -> [test.cpp:2:12]: (error) Returning object that points to local variable 's' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("const char * f(const std::string& s) {\n" @@ -2974,7 +2975,7 @@ class TestAutoVariables : public TestFixture { " std::string_view v = std::string();\n" " v.data();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2] -> [test.cpp:3]: (error) Using object that is a temporary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:37] -> [test.cpp:2:37] -> [test.cpp:3:5]: (error) Using object that is a temporary. [danglingTemporaryLifetime]\n", errout_str()); check("std::string convert(std::string_view sv) { return std::string{ sv }; }\n" // #11374 "auto f() {\n" @@ -2990,7 +2991,7 @@ class TestAutoVariables : public TestFixture { " std::string s = sv;\n" " return s;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2] -> [test.cpp:3]: (error) Using object that is a temporary.\n", + ASSERT_EQUALS("[test.cpp:2:30] -> [test.cpp:2:30] -> [test.cpp:3:17]: (error) Using object that is a temporary. [danglingTemporaryLifetime]\n", errout_str()); // #10833 @@ -2998,14 +2999,14 @@ class TestAutoVariables : public TestFixture { "const std::string& f(A* a) {\n" " return a ? a->s : \"\";\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("std::span f() {\n" " std::vector v{};\n" " return v;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'v' that will be invalid when returning.\n", + "[test.cpp:3:12] -> [test.cpp:2:22] -> [test.cpp:3:12]: (error) Returning object that points to local variable 'v' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("std::span f() {\n" @@ -3014,7 +3015,7 @@ class TestAutoVariables : public TestFixture { " return sp;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'v' that will be invalid when returning.\n", + "[test.cpp:3:20] -> [test.cpp:2:22] -> [test.cpp:4:12]: (error) Returning object that points to local variable 'v' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("std::span f() {\n" @@ -3022,7 +3023,7 @@ class TestAutoVariables : public TestFixture { " return std::span{v};\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'v' that will be invalid when returning.\n", + "[test.cpp:3:22] -> [test.cpp:2:22] -> [test.cpp:3:21]: (error) Returning object that points to local variable 'v' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("int f() {\n" @@ -3034,7 +3035,7 @@ class TestAutoVariables : public TestFixture { "return s.back()\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:4] -> [test.cpp:6]: (error) Using object that points to local variable 'v' that is out of scope.\n", + "[test.cpp:4:43] -> [test.cpp:4:26] -> [test.cpp:6:8]: (error) Using object that points to local variable 'v' that is out of scope. [invalidLifetime]\n", errout_str()); check("int f() {\n" @@ -3046,7 +3047,7 @@ class TestAutoVariables : public TestFixture { "return s.back()\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:4] -> [test.cpp:6]: (error) Using object that points to local variable 'v' that is out of scope.\n", + "[test.cpp:4:43] -> [test.cpp:4:26] -> [test.cpp:6:8]: (error) Using object that points to local variable 'v' that is out of scope. [invalidLifetime]\n", errout_str()); check("int f() {\n" @@ -3058,7 +3059,7 @@ class TestAutoVariables : public TestFixture { "return s.front()\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:4] -> [test.cpp:6]: (error) Using object that points to local variable 'v' that is out of scope.\n", + "[test.cpp:4:43] -> [test.cpp:4:26] -> [test.cpp:6:8]: (error) Using object that points to local variable 'v' that is out of scope. [invalidLifetime]\n", errout_str()); check("int f() {\n" @@ -3070,7 +3071,7 @@ class TestAutoVariables : public TestFixture { "return s.last(1)\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:4] -> [test.cpp:6]: (error) Using object that points to local variable 'v' that is out of scope.\n", + "[test.cpp:4:43] -> [test.cpp:4:26] -> [test.cpp:6:8]: (error) Using object that points to local variable 'v' that is out of scope. [invalidLifetime]\n", errout_str()); check("int f() {\n" @@ -3082,7 +3083,7 @@ class TestAutoVariables : public TestFixture { "return s.first(1)\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:4] -> [test.cpp:6]: (error) Using object that points to local variable 'v' that is out of scope.\n", + "[test.cpp:4:43] -> [test.cpp:4:26] -> [test.cpp:6:8]: (error) Using object that points to local variable 'v' that is out of scope. [invalidLifetime]\n", errout_str()); check("std::span f() {\n" // #12966 @@ -3090,7 +3091,7 @@ class TestAutoVariables : public TestFixture { " return a;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning pointer to local variable 'a' that will be invalid when returning.\n", + "[test.cpp:3:12] -> [test.cpp:2:9] -> [test.cpp:3:12]: (error) Returning pointer to local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("std::string_view f() {\n" // #10995 @@ -3098,7 +3099,7 @@ class TestAutoVariables : public TestFixture { " return a;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning pointer to local variable 'a' that will be invalid when returning.\n", + "[test.cpp:3:12] -> [test.cpp:2:10] -> [test.cpp:3:12]: (error) Returning pointer to local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); } @@ -3109,7 +3110,7 @@ class TestAutoVariables : public TestFixture { " return rp;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning pointer to local variable 'p' that will be invalid when returning.\n", + "[test.cpp:2:21] -> [test.cpp:1:29] -> [test.cpp:3:12]: (error) Returning pointer to local variable 'p' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("int* f();\n" // #11406 @@ -3125,7 +3126,7 @@ class TestAutoVariables : public TestFixture { " return ptr.get();\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Returning object that points to local variable 'ptr' that will be invalid when returning.\n", + "[test.cpp:4:19] -> [test.cpp:3:26] -> [test.cpp:4:19]: (error) Returning object that points to local variable 'ptr' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); // #12600 @@ -3141,13 +3142,13 @@ class TestAutoVariables : public TestFixture { " auto it = a.begin();\n" " return [=](){ return it; };\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:22] -> [test.cpp:4:26] -> [test.cpp:2:22] -> [test.cpp:4:12]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f(std::vector a) {\n" " auto it = a.begin();\n" " return [=](){ return it; };\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:22] -> [test.cpp:3:26] -> [test.cpp:1:25] -> [test.cpp:3:12]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct e {};\n" "e * j() {\n" @@ -3155,7 +3156,7 @@ class TestAutoVariables : public TestFixture { " return c;\n" "}"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Returning pointer to local variable 'c' that will be invalid when returning.\n", + "[test.cpp:4:12] -> [test.cpp:3:7] -> [test.cpp:4:12]: (error) Returning pointer to local variable 'c' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f(std::vector& a) {\n" @@ -3415,7 +3416,7 @@ class TestAutoVariables : public TestFixture { " MoreData mMoreData;\n" "};\n"); ASSERT_EQUALS( - "[test.cpp:11] -> [test.cpp:10] -> [test.cpp:11]: (error) Non-local variable 'mMoreData.data1' will use pointer to local variable 'data'.\n", + "[test.cpp:11:27] -> [test.cpp:10:14] -> [test.cpp:11:18]: (error) Non-local variable 'mMoreData.data1' will use pointer to local variable 'data'. [danglingLifetime]\n", errout_str()); // #10784 @@ -3476,7 +3477,7 @@ class TestAutoVariables : public TestFixture { " }\n" " *p = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:2] -> [test.cpp:7]: (error) Static variable 'p' will use pointer to local variable 'a'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:13] -> [test.cpp:2:9] -> [test.cpp:7:6]: (error) Static variable 'p' will use pointer to local variable 'a'. [danglingLifetime]\n", errout_str()); // #10902 check("void f() {\n" @@ -3484,7 +3485,7 @@ class TestAutoVariables : public TestFixture { " int y;\n" " x = &y;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Static variable 'x' will use pointer to local variable 'y'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:3:9] -> [test.cpp:4:5]: (error) Static variable 'x' will use pointer to local variable 'y'. [danglingLifetime]\n", errout_str()); } void danglingLifetimeFunction() { @@ -3493,7 +3494,7 @@ class TestAutoVariables : public TestFixture { " return std::ref(a);\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'a' that will be invalid when returning.\n", + "[test.cpp:3:21] -> [test.cpp:2:9] -> [test.cpp:3:20]: (error) Returning object that points to local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f() {\n" @@ -3501,7 +3502,7 @@ class TestAutoVariables : public TestFixture { " return std::make_tuple(std::ref(a));\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'a' that will be invalid when returning.\n", + "[test.cpp:3:37] -> [test.cpp:3:36] -> [test.cpp:2:9] -> [test.cpp:3:27]: (error) Returning object that points to local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("template\n" @@ -3513,7 +3514,7 @@ class TestAutoVariables : public TestFixture { " return by_value(v.begin());\n" "}"); ASSERT_EQUALS( - "[test.cpp:7] -> [test.cpp:7] -> [test.cpp:3] -> [test.cpp:3] -> [test.cpp:6] -> [test.cpp:7]: (error) Returning object that points to local variable 'v' that will be invalid when returning.\n", + "[test.cpp:7:28] -> [test.cpp:7:28] -> [test.cpp:3:12] -> [test.cpp:3:25] -> [test.cpp:6:22] -> [test.cpp:7:20]: (error) Returning object that points to local variable 'v' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("template\n" @@ -3525,7 +3526,7 @@ class TestAutoVariables : public TestFixture { " return by_value(v.begin());\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:7] -> [test.cpp:7] -> [test.cpp:3] -> [test.cpp:3] -> [test.cpp:6] -> [test.cpp:7]: (error) Returning object that points to local variable 'v' that will be invalid when returning.\n", + "[test.cpp:7:28] -> [test.cpp:7:28] -> [test.cpp:3:12] -> [test.cpp:3:25] -> [test.cpp:6:22] -> [test.cpp:7:20]: (error) Returning object that points to local variable 'v' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto by_ref(int& x) {\n" @@ -3536,7 +3537,7 @@ class TestAutoVariables : public TestFixture { " return by_ref(i);\n" "}"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:1] -> [test.cpp:2] -> [test.cpp:6] -> [test.cpp:5] -> [test.cpp:6]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", + "[test.cpp:2:12] -> [test.cpp:1:19] -> [test.cpp:2:25] -> [test.cpp:6:19] -> [test.cpp:5:9] -> [test.cpp:6:18]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto by_ref(const int& x) {\n" @@ -3590,7 +3591,7 @@ class TestAutoVariables : public TestFixture { " return a;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:9] -> [test.cpp:8] -> [test.cpp:10]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", + "[test.cpp:9:9] -> [test.cpp:8:9] -> [test.cpp:10:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct A {\n" @@ -3603,7 +3604,7 @@ class TestAutoVariables : public TestFixture { " return a;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:7] -> [test.cpp:6] -> [test.cpp:8]: (error, inconclusive) Returning object that points to local variable 'i' that will be invalid when returning.\n", + "[test.cpp:7:9] -> [test.cpp:6:9] -> [test.cpp:8:12]: (error, inconclusive) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct A {\n" @@ -3629,7 +3630,7 @@ class TestAutoVariables : public TestFixture { " return a;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:9] -> [test.cpp:8] -> [test.cpp:10]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", + "[test.cpp:9:9] -> [test.cpp:8:9] -> [test.cpp:10:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct A {\n" @@ -3644,7 +3645,7 @@ class TestAutoVariables : public TestFixture { " return a;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:9] -> [test.cpp:8] -> [test.cpp:10]: (error) Returning object that points to local variable 'v' that will be invalid when returning.\n", + "[test.cpp:9:9] -> [test.cpp:8:22] -> [test.cpp:10:12]: (error) Returning object that points to local variable 'v' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct A {\n" @@ -3659,7 +3660,7 @@ class TestAutoVariables : public TestFixture { " return a;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:9] -> [test.cpp:8] -> [test.cpp:10]: (error) Returning object that points to local variable 'v' that will be invalid when returning.\n", + "[test.cpp:9:9] -> [test.cpp:8:22] -> [test.cpp:10:12]: (error) Returning object that points to local variable 'v' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct A {\n" @@ -3672,7 +3673,7 @@ class TestAutoVariables : public TestFixture { " A a{0};\n" " return a;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:9]: (error) Returning object that will be invalid when returning.\n", + ASSERT_EQUALS("[test.cpp:8:9] -> [test.cpp:9:12]: (error) Returning object that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct A {\n" @@ -3686,7 +3687,7 @@ class TestAutoVariables : public TestFixture { " return A{i};\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:9] -> [test.cpp:8] -> [test.cpp:9]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", + "[test.cpp:9:14] -> [test.cpp:8:9] -> [test.cpp:9:13]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct A {\n" @@ -3712,7 +3713,7 @@ class TestAutoVariables : public TestFixture { " return A{s};\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:9] -> [test.cpp:8] -> [test.cpp:9]: (error) Returning object that points to local variable 's' that will be invalid when returning.\n", + "[test.cpp:9:14] -> [test.cpp:8:17] -> [test.cpp:9:13]: (error) Returning object that points to local variable 's' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct A {\n" @@ -3724,7 +3725,7 @@ class TestAutoVariables : public TestFixture { "A f() {\n" " return A{0};\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:8]: (error) Returning object that will be invalid when returning.\n", + ASSERT_EQUALS("[test.cpp:8:14] -> [test.cpp:8:13]: (error) Returning object that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct A {\n" @@ -3758,7 +3759,7 @@ class TestAutoVariables : public TestFixture { " return A(files);\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:8] -> [test.cpp:7] -> [test.cpp:8]: (error) Returning object that points to local variable 'files' that will be invalid when returning.\n", + "[test.cpp:8:14] -> [test.cpp:7:30] -> [test.cpp:8:13]: (error) Returning object that points to local variable 'files' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct S {\n" @@ -3803,7 +3804,7 @@ class TestAutoVariables : public TestFixture { " return A{i, i};\n" "}"); ASSERT_EQUALS( - "[test.cpp:7] -> [test.cpp:6] -> [test.cpp:7]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", + "[test.cpp:7:14] -> [test.cpp:6:9] -> [test.cpp:7:13]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct A {\n" @@ -3815,7 +3816,7 @@ class TestAutoVariables : public TestFixture { " return {i, i};\n" "}"); ASSERT_EQUALS( - "[test.cpp:7] -> [test.cpp:6] -> [test.cpp:7]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", + "[test.cpp:7:13] -> [test.cpp:6:9] -> [test.cpp:7:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct A {\n" @@ -3828,7 +3829,7 @@ class TestAutoVariables : public TestFixture { " return r;\n" "}"); ASSERT_EQUALS( - "[test.cpp:7] -> [test.cpp:6] -> [test.cpp:8]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", + "[test.cpp:7:9] -> [test.cpp:6:9] -> [test.cpp:8:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct A {\n" @@ -3841,7 +3842,7 @@ class TestAutoVariables : public TestFixture { " return r;\n" "}"); ASSERT_EQUALS( - "[test.cpp:7] -> [test.cpp:6] -> [test.cpp:8]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", + "[test.cpp:7:12] -> [test.cpp:6:9] -> [test.cpp:8:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct A {\n" @@ -3853,7 +3854,7 @@ class TestAutoVariables : public TestFixture { " return A{i, x};\n" "}"); ASSERT_EQUALS( - "[test.cpp:7] -> [test.cpp:6] -> [test.cpp:7]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", + "[test.cpp:7:14] -> [test.cpp:6:9] -> [test.cpp:7:13]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct A {\n" @@ -3912,7 +3913,7 @@ class TestAutoVariables : public TestFixture { " return v;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:6] -> [test.cpp:6] -> [test.cpp:6] -> [test.cpp:5] -> [test.cpp:8]: (error) Returning object that points to local variable 'a' that will be invalid when returning.\n", + "[test.cpp:6:30] -> [test.cpp:6:30] -> [test.cpp:6:21] -> [test.cpp:5:21] -> [test.cpp:8:12]: (error) Returning object that points to local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); } @@ -3923,8 +3924,8 @@ class TestAutoVariables : public TestFixture { " return v;\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n" - "[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", // duplicate + "[test.cpp:3:28] -> [test.cpp:3:28] -> [test.cpp:2:9] -> [test.cpp:4:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n" + "[test.cpp:3:32] -> [test.cpp:3:32] -> [test.cpp:2:9] -> [test.cpp:4:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", // duplicate errout_str()); check("std::vector f() {\n" @@ -3933,8 +3934,8 @@ class TestAutoVariables : public TestFixture { " return v;\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n" - "[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", // duplicate + "[test.cpp:3:25] -> [test.cpp:3:25] -> [test.cpp:2:9] -> [test.cpp:4:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n" + "[test.cpp:3:29] -> [test.cpp:3:29] -> [test.cpp:2:9] -> [test.cpp:4:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", // duplicate errout_str()); check("std::vector f() {\n" @@ -3942,8 +3943,8 @@ class TestAutoVariables : public TestFixture { " return {&i, &i};\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n" - "[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", // duplicate + "[test.cpp:3:13] -> [test.cpp:3:13] -> [test.cpp:2:9] -> [test.cpp:3:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n" + "[test.cpp:3:17] -> [test.cpp:3:17] -> [test.cpp:2:9] -> [test.cpp:3:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", // duplicate errout_str()); check("std::vector f(int& x) {\n" @@ -4023,7 +4024,7 @@ class TestAutoVariables : public TestFixture { " i += *x;\n" "}"); ASSERT_EQUALS( - "[test.cpp:1] -> [test.cpp:2] -> [test.cpp:5] -> [test.cpp:5] -> [test.cpp:5] -> [test.cpp:6]: (error) Using pointer that is a temporary.\n", + "[test.cpp:1:26] -> [test.cpp:2:12] -> [test.cpp:5:15] -> [test.cpp:5:14] -> [test.cpp:5:17] -> [test.cpp:6:11]: (error) Using pointer that is a temporary. [danglingTemporaryLifetime]\n", errout_str()); check("QString f() {\n" @@ -4032,7 +4033,7 @@ class TestAutoVariables : public TestFixture { " QString c = b;\n" " return c;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3] -> [test.cpp:4]: (error) Using pointer that is a temporary.\n", + ASSERT_EQUALS("[test.cpp:3:42] -> [test.cpp:3:34] -> [test.cpp:4:15]: (error) Using pointer that is a temporary. [danglingTemporaryLifetime]\n", errout_str()); check("auto f(std::string s) {\n" @@ -4040,7 +4041,7 @@ class TestAutoVariables : public TestFixture { " auto i = s.substr(4,5).begin();\n" " return *i;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3] -> [test.cpp:4]: (error) Using iterator that is a temporary.\n", + ASSERT_EQUALS("[test.cpp:3:33] -> [test.cpp:3:22] -> [test.cpp:4:13]: (error) Using iterator that is a temporary. [danglingTemporaryLifetime]\n", errout_str()); check("std::string f() {\n" @@ -4055,7 +4056,7 @@ class TestAutoVariables : public TestFixture { " const int &x = get_value();\n" " return x;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Reference to temporary returned.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16] -> [test.cpp:4:10]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("int get_value();\n" "const int &get_reference2() {\n" @@ -4063,7 +4064,7 @@ class TestAutoVariables : public TestFixture { " const int &x2 = x1;\n" " return x2;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3] -> [test.cpp:5]: (error) Reference to temporary returned.\n", + ASSERT_EQUALS("[test.cpp:4:17] -> [test.cpp:3:17] -> [test.cpp:5:10]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("const std::string& getState() {\n" @@ -4096,7 +4097,7 @@ class TestAutoVariables : public TestFixture { " const std::map::iterator& m = func().a_.m_.begin();\n" " (void)m->first;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:9] -> [test.cpp:10]: (error) Using iterator that is a temporary.\n", + ASSERT_EQUALS("[test.cpp:9:63] -> [test.cpp:9:49] -> [test.cpp:10:11]: (error) Using iterator that is a temporary. [danglingTemporaryLifetime]\n", errout_str()); check("void f(bool b) {\n" @@ -4142,7 +4143,7 @@ class TestAutoVariables : public TestFixture { " std::vector cargs = f({ \"0\", \"0\" });\n" " (void)cargs;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:4] -> [test.cpp:3] -> [test.cpp:1] -> [test.cpp:4] -> [test.cpp:9] -> [test.cpp:9] -> [test.cpp:10]: (error) Using object that is a temporary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:12] -> [test.cpp:4:47] -> [test.cpp:3:22] -> [test.cpp:1:58] -> [test.cpp:4:40] -> [test.cpp:9:34] -> [test.cpp:9:34] -> [test.cpp:10:11]: (error) Using object that is a temporary. [danglingTemporaryLifetime]\n", errout_str()); check("struct C {\n" // #9194 " const int& m;\n" @@ -4153,7 +4154,7 @@ class TestAutoVariables : public TestFixture { " C c(42);\n" " return c.get();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:7] -> [test.cpp:8]: (error) Using object that is a temporary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:9] -> [test.cpp:7:9] -> [test.cpp:8:12]: (error) Using object that is a temporary. [danglingTemporaryLifetime]\n", errout_str()); // #11298 check("struct S {\n" @@ -4238,7 +4239,7 @@ class TestAutoVariables : public TestFixture { " A** ap = &g();\n" " (*ap)->x;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:4] -> [test.cpp:5]: (error) Using pointer that is a temporary.\n", + ASSERT_EQUALS("[test.cpp:4:14] -> [test.cpp:4:16] -> [test.cpp:5:7]: (error) Using pointer that is a temporary. [danglingTemporaryLifetime]\n", errout_str()); check("struct A { int* x; };\n" @@ -4265,7 +4266,7 @@ class TestAutoVariables : public TestFixture { " A** ap = &b.g();\n" " (*ap)->x;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:5] -> [test.cpp:6]: (error) Using pointer that is a temporary.\n", + ASSERT_EQUALS("[test.cpp:5:14] -> [test.cpp:5:18] -> [test.cpp:6:7]: (error) Using pointer that is a temporary. [danglingTemporaryLifetime]\n", errout_str()); } @@ -4280,7 +4281,7 @@ class TestAutoVariables : public TestFixture { " return S(i).ptr();\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:4] -> [test.cpp:7] -> [test.cpp:7]: (error) Returning pointer that will be invalid when returning.\n", + "[test.cpp:4:25] -> [test.cpp:4:25] -> [test.cpp:7:13] -> [test.cpp:7:20]: (error) Returning pointer that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct Fred\n" @@ -4299,7 +4300,7 @@ class TestAutoVariables : public TestFixture { " return fred.get_x();\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:9] -> [test.cpp:9] -> [test.cpp:14] -> [test.cpp:13] -> [test.cpp:14]: (error) Returning pointer to local variable 'fred' that will be invalid when returning.\n", + "[test.cpp:9:16] -> [test.cpp:9:16] -> [test.cpp:14:12] -> [test.cpp:13:10] -> [test.cpp:14:22]: (error) Returning pointer to local variable 'fred' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct A {\n" @@ -4312,7 +4313,7 @@ class TestAutoVariables : public TestFixture { " return A().f();\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:4] -> [test.cpp:8] -> [test.cpp:8]: (error) Returning object that will be invalid when returning.\n", + "[test.cpp:4:16] -> [test.cpp:4:28] -> [test.cpp:8:13] -> [test.cpp:8:17]: (error) Returning object that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct A {\n" @@ -4337,7 +4338,7 @@ class TestAutoVariables : public TestFixture { " return A{&i}.f();\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:9] -> [test.cpp:9] -> [test.cpp:9] -> [test.cpp:4] -> [test.cpp:4] -> [test.cpp:8] -> [test.cpp:9]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", + "[test.cpp:9:14] -> [test.cpp:9:14] -> [test.cpp:9:13] -> [test.cpp:4:16] -> [test.cpp:4:18] -> [test.cpp:8:9] -> [test.cpp:9:19]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct S {\n" @@ -4369,7 +4370,7 @@ class TestAutoVariables : public TestFixture { " return ptr->val;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:9] -> [test.cpp:9] -> [test.cpp:9] -> [test.cpp:10]: (error) Using pointer that is a temporary.\n", + "[test.cpp:4:16] -> [test.cpp:9:16] -> [test.cpp:9:11] -> [test.cpp:9:13] -> [test.cpp:10:12]: (error) Using pointer that is a temporary. [danglingTemporaryLifetime]\n", errout_str()); check("struct A {\n" @@ -4383,7 +4384,7 @@ class TestAutoVariables : public TestFixture { " return r.val;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:8] -> [test.cpp:4] -> [test.cpp:8] -> [test.cpp:9]: (error) Using reference to dangling temporary.\n", + "[test.cpp:8:16] -> [test.cpp:4:16] -> [test.cpp:8:22] -> [test.cpp:9:12]: (error) Using reference to dangling temporary. [danglingTempReference]\n", errout_str()); } @@ -4396,7 +4397,7 @@ class TestAutoVariables : public TestFixture { " }\n" " f();\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4] -> [test.cpp:7]: (error) Using lambda that captures local variable 'b' that is out of scope.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:25] -> [test.cpp:4:13] -> [test.cpp:7:5]: (error) Using lambda that captures local variable 'b' that is out of scope. [invalidLifetime]\n", errout_str()); check("void f(bool b) {\n" " int* x;\n" @@ -4407,7 +4408,7 @@ class TestAutoVariables : public TestFixture { " x[3];\n" "}"); ASSERT_EQUALS( - "[test.cpp:5] -> [test.cpp:4] -> [test.cpp:7]: (error) Using pointer to local variable 'y' that is out of scope.\n", + "[test.cpp:5:9] -> [test.cpp:4:9] -> [test.cpp:7:3]: (error) Using pointer to local variable 'y' that is out of scope. [invalidLifetime]\n", errout_str()); check("void foo(int a) {\n" @@ -4517,7 +4518,7 @@ class TestAutoVariables : public TestFixture { " f(bar);\n" "}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:12]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:12:5]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); check("class Foo {};\n" "struct Bar {\n" @@ -4533,7 +4534,7 @@ class TestAutoVariables : public TestFixture { " }\n" " f(bar);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:11]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:11:5]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); check("class Foo {};\n" // #10750 "struct Bar {\n" @@ -4549,7 +4550,7 @@ class TestAutoVariables : public TestFixture { " }\n" " f(bar);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:10]: (error) Address of local auto-variable assigned to a function parameter.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:7]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); check("void f(std::string_view text);\n" // #11508 "void g() {\n" @@ -4582,7 +4583,7 @@ class TestAutoVariables : public TestFixture { " }\n" " *p = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4] -> [test.cpp:7]: (error) Using pointer to local variable 'x' that is out of scope.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:4:9] -> [test.cpp:7:4]: (error) Using pointer to local variable 'x' that is out of scope. [invalidLifetime]\n", errout_str()); // FP: don't warn in subfunction check("void f(struct KEY *key) {\n" @@ -4623,7 +4624,7 @@ class TestAutoVariables : public TestFixture { " dosth();\n" "}"); ASSERT_EQUALS( - "[test.cpp:5] -> [test.cpp:3] -> [test.cpp:4] -> [test.cpp:7]: (error) Using pointer to local variable 'item' that is out of scope.\n", + "[test.cpp:5:24] -> [test.cpp:3:47] -> [test.cpp:4:26] -> [test.cpp:7:9]: (error) Using pointer to local variable 'item' that is out of scope. [invalidLifetime]\n", errout_str()); // #6575 @@ -4648,7 +4649,7 @@ class TestAutoVariables : public TestFixture { " return *iPtr;\n" " return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4] -> [test.cpp:8]: (error) Using pointer to local variable 'x' that is out of scope.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:16] -> [test.cpp:4:13] -> [test.cpp:8:17]: (error) Using pointer to local variable 'x' that is out of scope. [invalidLifetime]\n", errout_str()); // #11753 check("int main(int argc, const char *argv[]) {\n" @@ -4659,7 +4660,7 @@ class TestAutoVariables : public TestFixture { " }\n" " std::cout << s;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4] -> [test.cpp:7]: (error) Using pointer to local variable 'buff' that is out of scope.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:26] -> [test.cpp:4:14] -> [test.cpp:7:18]: (error) Using pointer to local variable 'buff' that is out of scope. [invalidLifetime]\n", errout_str()); check("char* f(char* dst) {\n" " const char* src = \"abc\";\n" diff --git a/test/testbool.cpp b/test/testbool.cpp index b745f51c988..44031ca6d73 100644 --- a/test/testbool.cpp +++ b/test/testbool.cpp @@ -32,6 +32,7 @@ class TestBool : public TestFixture { const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).certainty(Certainty::inconclusive).build(); void run() override { + mNewTemplate = true; TEST_CASE(bitwiseOnBoolean); // if (bool & bool) TEST_CASE(incrementBoolean); TEST_CASE(assignBoolToPointer); @@ -97,22 +98,22 @@ class TestBool : public TestFixture { check("void foo(bool *p) {\n" " p = false;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Boolean value assigned to pointer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\n", errout_str()); check("void foo(bool *p) {\n" " p = (xq_intra_matrix :" " ctx->q_chroma_intra_matrix;\n" "}", dinit(CheckOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:3]: (error) Boolean value assigned to pointer.\n", errout_str()); + ASSERT_EQUALS("[test.c:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\n", errout_str()); // ticket #6588 (c++ mode) check("struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\n" @@ -163,7 +164,7 @@ class TestBool : public TestFixture { " ctx->q_intra_matrix :" " ctx->q_chroma_intra_matrix;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Boolean value assigned to pointer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\n", errout_str()); // ticket #6665 check("void pivot_big(char *first, int compare(const void *, const void *)) {\n" @@ -179,24 +180,24 @@ class TestBool : public TestFixture { " p = b;\n" " p = &b;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Boolean value assigned to pointer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\n", errout_str()); } void assignBoolToFloat() { check("void foo1() {\n" " double d = false;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Boolean value assigned to floating point variable.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\n", errout_str()); check("void foo2() {\n" " float d = true;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Boolean value assigned to floating point variable.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\n", errout_str()); check("void foo3() {\n" " long double d = (2>1);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Boolean value assigned to floating point variable.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:19]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\n", errout_str()); // stability - don't crash: check("void foo4() {\n" @@ -211,7 +212,7 @@ class TestBool : public TestFixture { " S s = {0};\n" " s.p = true;\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (style) Boolean value assigned to floating point variable.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:9]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\n", errout_str()); check("struct S {\n" " float* p[1];\n" @@ -220,7 +221,7 @@ class TestBool : public TestFixture { " S s = {0};\n" " *s.p[0] = true;\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (style) Boolean value assigned to floating point variable.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\n", errout_str()); } void comparisonOfBoolExpressionWithInt1() { @@ -228,7 +229,7 @@ class TestBool : public TestFixture { " if ((x && 0x0f)==6)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int x) {\n" " if ((x && 0x0f)==0)\n" @@ -240,7 +241,7 @@ class TestBool : public TestFixture { " if ((x || 0x0f)==6)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int x) {\n" " if ((x || 0x0f)==0)\n" @@ -265,29 +266,29 @@ class TestBool : public TestFixture { " if ((5 && x)==3)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int x) {\n" " if ((5 && x)==3 || (8 && x)==9)\n" " a++;\n" "}"); ASSERT_EQUALS( - "[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n" - "[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", // duplicate + "[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n" + "[test.cpp:2:32]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", // duplicate errout_str()); check("void f(int x) {\n" " if ((5 && x)!=3)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int x) {\n" " if ((5 && x) > 3)\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int x) {\n" " if ((5 && x) > 0)\n" @@ -300,7 +301,7 @@ class TestBool : public TestFixture { " a++;\n" "}" ); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int x) {\n" " if ((5 && x) < 1)\n" @@ -313,7 +314,7 @@ class TestBool : public TestFixture { " a++;\n" "}" ); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int x) {\n" @@ -327,7 +328,7 @@ class TestBool : public TestFixture { " a++;\n" "}" ); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int x) {\n" " if (1 > (5 && x))\n" @@ -340,55 +341,55 @@ class TestBool : public TestFixture { " a++;\n" "}" ); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(bool x ) {\n" " if ( x > false )\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\n", errout_str()); check("void f(bool x ) {\n" " if ( false < x )\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\n", errout_str()); check("void f(bool x ) {\n" " if ( x < false )\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\n", errout_str()); check("void f(bool x ) {\n" " if ( false > x )\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\n", errout_str()); check("void f(bool x ) {\n" " if ( x >= false )\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\n", errout_str()); check("void f(bool x ) {\n" " if ( false >= x )\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\n", errout_str()); check("void f(bool x ) {\n" " if ( x <= false )\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\n", errout_str()); check("void f(bool x ) {\n" " if ( false <= x )\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\n", errout_str()); check("typedef int (*func)(bool invert);\n" "void x(int, func f);\n" @@ -413,14 +414,14 @@ class TestBool : public TestFixture { " printf(\"x not equal to 10\");\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int x) {\n" " if (!x != 10) {\n" " printf(\"x not equal to 10\");\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int x) {\n" " if (x != 10) {\n" @@ -434,14 +435,14 @@ class TestBool : public TestFixture { " printf(\"x not equal to 10\");\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int x) {\n" " if (10 != !x) {\n" " printf(\"x not equal to 10\");\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int x, int y) {\n" " if (y != !x) {\n" @@ -484,7 +485,7 @@ class TestBool : public TestFixture { ASSERT_EQUALS("",errout_str()); check("void f(int a, int b, int c) { if (1 < !(a+b)) {} }"); - ASSERT_EQUALS("[test.cpp:1]: (warning) Comparison of a boolean expression with an integer.\n",errout_str()); + ASSERT_EQUALS("[test.cpp:1:37]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\n",errout_str()); } void comparisonOfBoolExpressionWithInt3() { @@ -499,7 +500,7 @@ class TestBool : public TestFixture { check("void f() {\n" " for(int i = 4; i > -1 < 5 ; --i) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:25]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int a, int b, int c) {\n" " return (a > b) < c;\n" @@ -540,7 +541,7 @@ class TestBool : public TestFixture { check("int f() {\n" " return (a < b) != 42U;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); } void checkComparisonOfFuncReturningBool1() { @@ -564,7 +565,7 @@ class TestBool : public TestFixture { " else\n" " return true;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\n", errout_str()); } void checkComparisonOfFuncReturningBool2() { @@ -589,8 +590,8 @@ class TestBool : public TestFixture { " else\n" " return false;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n" - "[test.cpp:11]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\n" + "[test.cpp:11:7]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\n", errout_str()); } void checkComparisonOfFuncReturningBool3() { @@ -601,8 +602,8 @@ class TestBool : public TestFixture { " }\n" "}\n" "bool compare(int temp);"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n" - "[test.cpp:3]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n" + "[test.cpp:3:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\n", errout_str()); } void checkComparisonOfFuncReturningBool4() { @@ -627,7 +628,7 @@ class TestBool : public TestFixture { " else\n" " return false;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\n", errout_str()); } void checkComparisonOfFuncReturningBool5() { @@ -651,7 +652,7 @@ class TestBool : public TestFixture { " else\n" " return true;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\n", errout_str()); } void checkComparisonOfFuncReturningBool6() { @@ -689,7 +690,7 @@ class TestBool : public TestFixture { " }\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:20]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\n", errout_str()); check("int compare1(int temp);\n" "namespace Foo {\n" @@ -724,10 +725,10 @@ class TestBool : public TestFixture { " if ((int)c1.isEmpty() < (int)c2.isEmpty()) {}\n" " if (static_cast(c1.isEmpty()) < static_cast(c2.isEmpty())) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n" - "[test.cpp:7]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n" - "[test.cpp:8]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n" - "[test.cpp:9]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n", + ASSERT_EQUALS("[test.cpp:6:20]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\n" + "[test.cpp:7:20]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\n" + "[test.cpp:8:24]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\n" + "[test.cpp:9:36]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\n", errout_str()); } @@ -740,7 +741,7 @@ class TestBool : public TestFixture { " ;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\n", errout_str()); // op: < check("int main(void){\n" " bool a = true;\n" @@ -749,7 +750,7 @@ class TestBool : public TestFixture { " ;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\n", errout_str()); // op: >= check("int main(void){\n" " bool a = true;\n" @@ -758,7 +759,7 @@ class TestBool : public TestFixture { " ;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\n", errout_str()); // op: <= check("int main(void){\n" " bool a = true;\n" @@ -767,7 +768,7 @@ class TestBool : public TestFixture { " ;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\n", errout_str()); } void checkComparisonOfFuncReturningBoolIntegrationTest1() { // #7798 @@ -806,78 +807,78 @@ class TestBool : public TestFixture { " return false;\n" "}\n"; check(code); - ASSERT_EQUALS("[test.cpp:5]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\n", errout_str()); } void bitwiseOnBoolean() { // 3062 check("void f(_Bool a, _Bool b) {\n" " if(a & b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\n", errout_str()); check("void f(_Bool a, _Bool b) {\n" " if(a | b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\n", errout_str()); check("void f(bool a, bool b) {\n" " if(a & !b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\n", errout_str()); check("void f(bool a, bool b) {\n" " if(a | !b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\n", errout_str()); check("bool a, b;\n" "void f() {\n" " if(a & b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\n", errout_str()); check("bool a, b;\n" "void f() {\n" " if(a & !b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\n", errout_str()); check("bool a, b;\n" "void f() {\n" " if(a | b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\n", errout_str()); check("bool a, b;\n" "void f() {\n" " if(a | !b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\n", errout_str()); check("void f(bool a, int b) {\n" " if(a & b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\n", errout_str()); check("void f(int a, bool b) {\n" " if(a & b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '&&'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\n", errout_str()); check("void f(int a, int b) {\n" " if((a > 0) & (b < 0)) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a>0' is used in bitwise operation. Did you mean '&&'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (style, inconclusive) Boolean expression 'a>0' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\n", errout_str()); check("void f(bool a, int b) {\n" " if(a | b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\n", errout_str()); check("void f(int a, bool b) {\n" " if(a | b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\n", errout_str()); check("int f(bool a, int b) {\n" " return a | b;\n" @@ -887,7 +888,7 @@ class TestBool : public TestFixture { check("bool f(bool a, int b) {\n" " return a | b;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\n", errout_str()); check("void f(int a, int b) {\n" " if(a & b) {}\n" @@ -920,7 +921,7 @@ class TestBool : public TestFixture { "void f(bool b) {\n" " if (g() | b) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\n", errout_str()); check("int g();\n" "void f(bool b) {\n" @@ -932,7 +933,7 @@ class TestBool : public TestFixture { "bool f(bool b, bool c) {\n" " return b | g() | c;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. Did you mean '||'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:20]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\n", errout_str()); check("void f(int i) {\n" // #4233 " bool b = true, c = false;\n" @@ -940,8 +941,8 @@ class TestBool : public TestFixture { " c |= i;\n" " if (b || c) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation.\n" - "[test.cpp:4]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation.\n", + ASSERT_EQUALS("[test.cpp:3:7]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. [bitwiseOnBoolean]\n" + "[test.cpp:4:7]: (style, inconclusive) Boolean expression 'c' is used in bitwise operation. [bitwiseOnBoolean]\n", errout_str()); check("void f(int i, int j, bool b) {\n" @@ -971,22 +972,22 @@ class TestBool : public TestFixture { void incrementBoolean() { check("bool bValue = true;\n" "void f() { bValue++; }"); - ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\n", errout_str()); check("void f(bool test){\n" " test++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\n", errout_str()); check("void f(bool* test){\n" " (*test)++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:6]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\n", errout_str()); check("void f(bool* test){\n" " test[0]++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\n", errout_str()); check("void f(int test){\n" " test++;\n" @@ -1000,14 +1001,14 @@ class TestBool : public TestFixture { " printf(\"foo\");\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(bool x) {\n" " if (10 >= x) {\n" " printf(\"foo\");\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(bool x) {\n" " if (x != 0) {\n" @@ -1027,14 +1028,14 @@ class TestBool : public TestFixture { " printf(\"foo\");\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(bool x) {\n" " if (x == 10) {\n" " printf(\"foo\");\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(bool x) {\n" " if (x == 0) {\n" @@ -1083,7 +1084,7 @@ class TestBool : public TestFixture { " printf(\"foo\");\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\n", errout_str()); check("void f(int y) {\n" " if (true == y) {\n" @@ -1104,7 +1105,7 @@ class TestBool : public TestFixture { " printf(\"foo\");\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); } void comparisonOfBoolWithInt4() { @@ -1211,32 +1212,32 @@ class TestBool : public TestFixture { check("void f(char *p) {\n" " if (p+1){}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\n", errout_str()); check("void f(char *p) {\n" " do {} while (p+1);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:19]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\n", errout_str()); check("void f(char *p) {\n" " while (p-1) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\n", errout_str()); check("void f(char *p) {\n" " for (int i = 0; p+1; i++) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:22]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\n", errout_str()); check("void f(char *p) {\n" " if (p && p+1){}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\n", errout_str()); check("void f(char *p) {\n" " if (p+2 || p) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\n", errout_str()); } void returnNonBool() { @@ -1253,17 +1254,17 @@ class TestBool : public TestFixture { check("bool f(void) {\n" " return 2;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Non-boolean value returned from function returning bool\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n", errout_str()); check("bool f(void) {\n" " return -1;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Non-boolean value returned from function returning bool\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n", errout_str()); check("bool f(void) {\n" " return 1 + 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Non-boolean value returned from function returning bool\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n", errout_str()); check("bool f(void) {\n" " int x = 0;\n" @@ -1275,7 +1276,7 @@ class TestBool : public TestFixture { " int x = 10;\n" " return x;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n", errout_str()); check("bool f(void) {\n" " return 2 < 1;\n" @@ -1296,15 +1297,15 @@ class TestBool : public TestFixture { " ret = 3;\n" " return ret;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (style) Non-boolean value returned from function returning bool\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n", errout_str()); check("bool f(void) {\n" " if (a)\n" " return 3;\n" " return 4;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n" - "[test.cpp:4]: (style) Non-boolean value returned from function returning bool\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n" + "[test.cpp:4:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n", errout_str()); check("bool f(void) {\n" " return;\n" @@ -1323,7 +1324,7 @@ class TestBool : public TestFixture { " auto x = [](void) { return -1; };\n" " return 2;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n", errout_str()); check("bool f(void) {\n" " auto x = [](void) -> int { return -1; };\n" @@ -1335,7 +1336,7 @@ class TestBool : public TestFixture { " auto x = [](void) -> int { return -1; };\n" " return 2;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n", errout_str()); } void returnNonBoolLogicalOp() { @@ -1360,7 +1361,7 @@ class TestBool : public TestFixture { " public:\n" " bool f() { return -1;}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:20]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n", errout_str()); check("bool f() {\n" " struct X {\n" @@ -1387,8 +1388,8 @@ class TestBool : public TestFixture { " };\n" " return -1;\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (style) Non-boolean value returned from function returning bool\n" - "[test.cpp:4]: (style) Non-boolean value returned from function returning bool\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n" + "[test.cpp:4:24]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n", errout_str()); } }; diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 929fea77fcf..8f8e7d6d6c1 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -39,6 +39,7 @@ class TestNullPointer : public TestFixture { const Settings settings = settingsBuilder().library("std.cfg").severity(Severity::warning).build(); void run() override { + mNewTemplate = true; TEST_CASE(nullpointerAfterLoop); TEST_CASE(nullpointer1); TEST_CASE(nullpointer2); @@ -218,7 +219,7 @@ class TestNullPointer : public TestFixture { " while (tok);\n" " tok = tok->next();\n" "}", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'tok' is redundant or there is possible null pointer dereference: tok.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12] -> [test.cpp:4:11]: (warning) Either the condition 'tok' is redundant or there is possible null pointer dereference: tok. [nullPointerRedundantCheck]\n", errout_str()); // #2681 { @@ -232,7 +233,7 @@ class TestNullPointer : public TestFixture { "}\n"; check(code); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (warning) Either the condition 'tok' is redundant or there is possible null pointer dereference: tok.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12] -> [test.cpp:6:9]: (warning) Either the condition 'tok' is redundant or there is possible null pointer dereference: tok. [nullPointerRedundantCheck]\n", errout_str()); } check("void foo()\n" @@ -298,7 +299,7 @@ class TestNullPointer : public TestFixture { " }\n" " tok->str();\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Either the condition 'tok' is redundant or there is possible null pointer dereference: tok.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16] -> [test.cpp:5:5]: (warning) Either the condition 'tok' is redundant or there is possible null pointer dereference: tok. [nullPointerRedundantCheck]\n", errout_str()); check("int foo(const Token *tok)\n" "{\n" @@ -334,7 +335,7 @@ class TestNullPointer : public TestFixture { " if (d && d->i != 0) {}\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:6]: (warning) Either the condition 'd' is redundant or there is possible null pointer dereference: d.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:13] -> [test.cpp:6:40]: (warning) Either the condition 'd' is redundant or there is possible null pointer dereference: d. [nullPointerRedundantCheck]\n", errout_str()); } void nullpointer1() { @@ -394,7 +395,7 @@ class TestNullPointer : public TestFixture { " if (!abc)\n" " ;\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:3:13]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(struct ABC *abc) {\n" " bar(abc->a);\n" @@ -403,9 +404,9 @@ class TestNullPointer : public TestFixture { " if (!abc)\n" " ;\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:2]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc.\n" - "[test.cpp:5] -> [test.cpp:3]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc.\n" - "[test.cpp:5] -> [test.cpp:4]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:2:9]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n" + "[test.cpp:5:9] -> [test.cpp:3:12]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n" + "[test.cpp:5:9] -> [test.cpp:4:15]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(ABC *abc) {\n" " if (abc->a == 3) {\n" @@ -414,7 +415,7 @@ class TestNullPointer : public TestFixture { " if (abc) {}\n" "}"); ASSERT_EQUALS( - "[test.cpp:5] -> [test.cpp:2]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc.\n", + "[test.cpp:5:9] -> [test.cpp:2:9]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n", errout_str()); check("void f(ABC *abc) {\n" @@ -423,7 +424,7 @@ class TestNullPointer : public TestFixture { " }\n" " if (!abc);\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:2]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:2:9]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n", errout_str()); // TODO: False negative if member of member is dereferenced check("void foo(ABC *abc) {\n" @@ -439,7 +440,7 @@ class TestNullPointer : public TestFixture { " ;\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc.\n", + "[test.cpp:3:9] -> [test.cpp:2:5]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n", errout_str()); // ok dereferencing in a condition @@ -564,7 +565,7 @@ class TestNullPointer : public TestFixture { " if (abc) { }\n" "}"); ASSERT_EQUALS( - "[test.cpp:5] -> [test.cpp:3]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc.\n", + "[test.cpp:5:9] -> [test.cpp:3:5]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n", errout_str()); // #2641 - local pointer, function call @@ -574,7 +575,7 @@ class TestNullPointer : public TestFixture { " if (abc) { }\n" "}"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:2]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc.\n", + "[test.cpp:4:9] -> [test.cpp:2:5]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n", errout_str()); // #2691 - switch/break @@ -623,7 +624,7 @@ class TestNullPointer : public TestFixture { "}"; check(code); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2]: (warning) Either the condition 'fred' is redundant or there is possible null pointer dereference: fred.\n", + "[test.cpp:3:9] -> [test.cpp:2:5]: (warning) Either the condition 'fred' is redundant or there is possible null pointer dereference: fred. [nullPointerRedundantCheck]\n", errout_str()); } @@ -655,7 +656,7 @@ class TestNullPointer : public TestFixture { " if (!p)\n" " ;\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:3:6]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(int *p)\n" "{\n" @@ -663,7 +664,7 @@ class TestNullPointer : public TestFixture { " if (p) { }\n" "}"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:3]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p.\n", + "[test.cpp:4:9] -> [test.cpp:3:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(int *p)\n" @@ -672,7 +673,7 @@ class TestNullPointer : public TestFixture { " if (p || q) { }\n" "}"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:3]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p.\n", + "[test.cpp:4:9] -> [test.cpp:3:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(int *p)\n" @@ -681,7 +682,7 @@ class TestNullPointer : public TestFixture { " if (!p)\n" " ;\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:3:10]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(char *p)\n" "{\n" @@ -689,14 +690,14 @@ class TestNullPointer : public TestFixture { " if (!p)\n" " ;\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:3:12]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(char *p)\n" "{\n" " if (*p == 0) { }\n" " if (!p) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:3:10]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); // no error check("void foo()\n" @@ -750,7 +751,7 @@ class TestNullPointer : public TestFixture { " ;\n" "}"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:3]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p.\n", + "[test.cpp:4:9] -> [test.cpp:3:21]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); // while @@ -765,7 +766,7 @@ class TestNullPointer : public TestFixture { " while (p) { }\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p.\n", + "[test.cpp:3:12] -> [test.cpp:2:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); // Ticket #3125 @@ -844,7 +845,7 @@ class TestNullPointer : public TestFixture { " if (p) { *p = 0; }\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:2]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p.\n", + "[test.cpp:3:12] -> [test.cpp:2:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(x *p)\n" @@ -911,7 +912,7 @@ class TestNullPointer : public TestFixture { " if (item) { }\n" "}"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:2]: (warning) Either the condition 'item' is redundant or there is possible null pointer dereference: item.\n", + "[test.cpp:4:9] -> [test.cpp:2:5]: (warning) Either the condition 'item' is redundant or there is possible null pointer dereference: item. [nullPointerRedundantCheck]\n", errout_str()); check("BOOL GotoFlyAnchor()\n" // #2243 @@ -991,7 +992,7 @@ class TestNullPointer : public TestFixture { check("struct S { struct T { char c; } *p; };\n" // #6541 "char f(S* s) { return s->p ? 'a' : s->p->c; }\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (warning) Either the condition 's->p' is redundant or there is possible null pointer dereference: s->p.\n", + ASSERT_EQUALS("[test.cpp:2:24] -> [test.cpp:2:37]: (warning) Either the condition 's->p' is redundant or there is possible null pointer dereference: s->p. [nullPointerRedundantCheck]\n", errout_str()); } @@ -1024,12 +1025,12 @@ class TestNullPointer : public TestFixture { check("static void foo() {\n" " int &r = *(int*)0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference: (int*)0\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (error) Null pointer dereference: (int*)0 [nullPointer]\n", errout_str()); check("static void foo(int x) {\n" " int y = 5 + *(int*)0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference: (int*)0\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (error) Null pointer dereference: (int*)0 [nullPointer]\n", errout_str()); { const char code[] = "static void foo() {\n" @@ -1038,13 +1039,13 @@ class TestNullPointer : public TestFixture { "}\n"; check(code); - ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference: abc\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Null pointer dereference: abc [nullPointer]\n", errout_str()); } check("static void foo() {\n" " std::cout << *(int*)0;" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference: (int*)0\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:19]: (error) Null pointer dereference: (int*)0 [nullPointer]\n", errout_str()); check("void f()\n" "{\n" @@ -1054,12 +1055,12 @@ class TestNullPointer : public TestFixture { " }\n" " c[0] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Null pointer dereference: c\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:5]: (error) Null pointer dereference: c [nullPointer]\n", errout_str()); check("static void foo() {\n" " if (3 > *(int*)0);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference: (int*)0\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (error) Null pointer dereference: (int*)0 [nullPointer]\n", errout_str()); // no false positive.. check("static void foo()\n" @@ -1116,7 +1117,7 @@ class TestNullPointer : public TestFixture { " *Q=1;\n" " return Q;\n" "}"); - ASSERT_EQUALS("[test.cpp:12]: (warning) Possible null pointer dereference: Q\n", errout_str()); + ASSERT_EQUALS("[test.cpp:12:6]: (warning) Possible null pointer dereference: Q [nullPointer]\n", errout_str()); // Ticket #2052 (false positive for 'else continue;') check("void f() {\n" @@ -1136,7 +1137,7 @@ class TestNullPointer : public TestFixture { " f = 0;\n" " f();\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference: f\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:5]: (error) Null pointer dereference: f [nullPointer]\n", errout_str()); check("int* g();\n" // #11007 "int* f() {\n" @@ -1154,7 +1155,7 @@ class TestNullPointer : public TestFixture { " int x = *p + 1;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:18]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); check("void f(int a) {\n" " const char *p = 0;\n" @@ -1179,7 +1180,7 @@ class TestNullPointer : public TestFixture { " Fred *fred = NULL;\n" " fred->do_something();\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference: fred\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Null pointer dereference: fred [nullPointer]\n", errout_str()); // ticket #3570 - parsing of conditions { @@ -1203,7 +1204,7 @@ class TestNullPointer : public TestFixture { " p = q;\n" " if (p || *p) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Possible null pointer dereference: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:15]: (warning) Possible null pointer dereference: p [nullPointer]\n", errout_str()); } // ticket #8831 - FP triggered by if/return/else sequence @@ -1226,7 +1227,7 @@ class TestNullPointer : public TestFixture { " int* const crash = 0;\n" " *crash = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference: crash\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: (error) Null pointer dereference: crash [nullPointer]\n", errout_str()); } // Ticket #2350 @@ -1259,7 +1260,7 @@ class TestNullPointer : public TestFixture { " argv32[i] = 0;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:10]: (warning) Possible null pointer dereference: argv32\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:9]: (warning) Possible null pointer dereference: argv32 [nullPointer]\n", errout_str()); // #2231 - error if assignment in loop is not used // extracttests.start: int y[20]; @@ -1275,7 +1276,7 @@ class TestNullPointer : public TestFixture { "\n" " *p = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:11]: (warning) Possible null pointer dereference: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:11:6]: (warning) Possible null pointer dereference: p [nullPointer]\n", errout_str()); } void nullpointer7() { @@ -1293,7 +1294,7 @@ class TestNullPointer : public TestFixture { " std::string * x = 0;\n" " *x = \"test\";\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:4]: (error) Null pointer dereference: x [nullPointer]\n", errout_str()); } void nullpointer10() { @@ -1303,7 +1304,7 @@ class TestNullPointer : public TestFixture { " struct my_type* p = 0;\n" " p->x = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:3]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); } void nullpointer11() { // ticket #2812 @@ -1315,7 +1316,7 @@ class TestNullPointer : public TestFixture { " p = 0;\n" " return p->x;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); } void nullpointer12() { // ticket #2470, #4035 @@ -1326,7 +1327,7 @@ class TestNullPointer : public TestFixture { "}\n"; check(code); // C++ file => nullptr means NULL - ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (error) Null pointer dereference: i [nullPointer]\n", errout_str()); check(code, dinit(CheckOptions, $.cpp = false)); // C file => nullptr does not mean NULL ASSERT_EQUALS("", errout_str()); @@ -1376,7 +1377,7 @@ class TestNullPointer : public TestFixture { " i++;\n" " };\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference: str\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (error) Null pointer dereference: str [nullPointer]\n", errout_str()); } void nullpointer19() { // #3811 @@ -1437,7 +1438,7 @@ class TestNullPointer : public TestFixture { " if (data == 1 && array[i] == 0)\n" " std::cout << \"test\";\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: array\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:22]: (error) Null pointer dereference: array [nullPointer]\n", errout_str()); } void nullpointer26() { // #3589 @@ -1468,7 +1469,7 @@ class TestNullPointer : public TestFixture { " *pointer_=0;\n" " return *this;\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Null pointer dereference: pointer_\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:6]: (error) Null pointer dereference: pointer_ [nullPointer]\n", errout_str()); } void nullpointer28() { // #6491 @@ -1479,7 +1480,7 @@ class TestNullPointer : public TestFixture { " return i;\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 's' is redundant or there is possible null pointer dereference: s.\n", + "[test.cpp:3:11] -> [test.cpp:4:15]: (warning) Either the condition 's' is redundant or there is possible null pointer dereference: s. [nullPointerRedundantCheck]\n", errout_str()); } @@ -1496,7 +1497,7 @@ class TestNullPointer : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:3]: (warning) Either the condition 'values' is redundant or there is possible null pointer dereference: values.\n", + "[test.cpp:4:7] -> [test.cpp:3:3]: (warning) Either the condition 'values' is redundant or there is possible null pointer dereference: values. [nullPointerRedundantCheck]\n", errout_str()); } @@ -1541,7 +1542,7 @@ class TestNullPointer : public TestFixture { " return *p1;\n" " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:6]: (warning) Either the condition 'ptr' is redundant or there is possible null pointer dereference: p1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:6] -> [test.cpp:6:13]: (warning) Either the condition 'ptr' is redundant or there is possible null pointer dereference: p1. [nullPointerRedundantCheck]\n", errout_str()); } void nullpointer33() { @@ -1551,7 +1552,7 @@ class TestNullPointer : public TestFixture { " else\n" " *x = 3;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (warning) Either the condition 'x!=nullptr' is redundant or there is possible null pointer dereference: x.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:5:10]: (warning) Either the condition 'x!=nullptr' is redundant or there is possible null pointer dereference: x. [nullPointerRedundantCheck]\n", errout_str()); } void nullpointer34() { @@ -1642,7 +1643,7 @@ class TestNullPointer : public TestFixture { " *(a->x);\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'a->x==NULL' is redundant or there is possible null pointer dereference: a->x.\n", + "[test.cpp:3:14] -> [test.cpp:4:8]: (warning) Either the condition 'a->x==NULL' is redundant or there is possible null pointer dereference: a->x. [nullPointerRedundantCheck]\n", errout_str()); } @@ -1653,7 +1654,7 @@ class TestNullPointer : public TestFixture { " *(a->x);\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'a->x==nullptr' is redundant or there is possible null pointer dereference: a->x.\n", + "[test.cpp:3:14] -> [test.cpp:4:8]: (warning) Either the condition 'a->x==nullptr' is redundant or there is possible null pointer dereference: a->x. [nullPointerRedundantCheck]\n", errout_str()); } @@ -1664,7 +1665,7 @@ class TestNullPointer : public TestFixture { " *(a->g());\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'a->g()==nullptr' is redundant or there is possible null pointer dereference: a->g().\n", + "[test.cpp:3:16] -> [test.cpp:4:11]: (warning) Either the condition 'a->g()==nullptr' is redundant or there is possible null pointer dereference: a->g(). [nullPointerRedundantCheck]\n", errout_str()); check("struct A { int * g(); };\n" @@ -1682,7 +1683,7 @@ class TestNullPointer : public TestFixture { " *(a->g());\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'a->g()==nullptr' is redundant or there is possible null pointer dereference: a->g().\n", + "[test.cpp:3:16] -> [test.cpp:4:11]: (warning) Either the condition 'a->g()==nullptr' is redundant or there is possible null pointer dereference: a->g(). [nullPointerRedundantCheck]\n", errout_str()); } @@ -1773,7 +1774,7 @@ class TestNullPointer : public TestFixture { " const int *const a = p;\n" " if(!a){}\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (warning) Either the condition '!a' is redundant or there is possible null pointer dereference: p.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7] -> [test.cpp:2:8]: (warning) Either the condition '!a' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); } void nullpointer48() { @@ -1792,7 +1793,7 @@ class TestNullPointer : public TestFixture { " *p +=2;\n" " if(n < 120) *q+=12;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Possible null pointer dereference: q\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:18]: (warning) Possible null pointer dereference: q [nullPointer]\n", errout_str()); check("void f(int *p, int n) {\n" " int *q = 0;\n" @@ -1815,7 +1816,7 @@ class TestNullPointer : public TestFixture { " }\n" "}"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:6]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p.\n", + "[test.cpp:2:8] -> [test.cpp:6:18]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); } @@ -1881,7 +1882,7 @@ class TestNullPointer : public TestFixture { " if (!d) c.x = &a;\n" " return *c.x;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (warning) Possible null pointer dereference: c.x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:14]: (warning) Possible null pointer dereference: c.x [nullPointer]\n", errout_str()); } void nullpointer53() { @@ -1893,7 +1894,7 @@ class TestNullPointer : public TestFixture { "void bar() {\n" " f(0, 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Possible null pointer dereference: params\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (warning) Possible null pointer dereference: params [nullPointer]\n", errout_str()); } void nullpointer54() { @@ -1920,7 +1921,7 @@ class TestNullPointer : public TestFixture { " if (tok3 && tok3->str() == \"(\") {}\n" "}"); ASSERT_EQUALS( - "[test.cpp:5] -> [test.cpp:3]: (warning) Either the condition 'tok3' is redundant or there is possible null pointer dereference: tok3.\n", + "[test.cpp:5:9] -> [test.cpp:3:12]: (warning) Either the condition 'tok3' is redundant or there is possible null pointer dereference: tok3. [nullPointerRedundantCheck]\n", errout_str()); check("void f(int* t1, int* t2) {\n" @@ -2214,7 +2215,7 @@ class TestNullPointer : public TestFixture { " }\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:5]: (warning) Either the condition 'scope' is redundant or there is possible null pointer dereference: scope.\n", + "[test.cpp:3:12] -> [test.cpp:5:22]: (warning) Either the condition 'scope' is redundant or there is possible null pointer dereference: scope. [nullPointerRedundantCheck]\n", errout_str()); check("void f(const Scope *scope) {\n" @@ -2228,7 +2229,7 @@ class TestNullPointer : public TestFixture { " }\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:8]: (warning) Either the condition 'scope' is redundant or there is possible null pointer dereference: scope.\n", + "[test.cpp:3:12] -> [test.cpp:8:22]: (warning) Either the condition 'scope' is redundant or there is possible null pointer dereference: scope. [nullPointerRedundantCheck]\n", errout_str()); check("struct a {\n" @@ -2357,7 +2358,7 @@ class TestNullPointer : public TestFixture { " if (!flag1 && flag2)\n" " (*ptr)++;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:10]: (warning) Either the condition 'ptr!=nullptr' is redundant or there is possible null pointer dereference: ptr.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:17] -> [test.cpp:10:11]: (warning) Either the condition 'ptr!=nullptr' is redundant or there is possible null pointer dereference: ptr. [nullPointerRedundantCheck]\n", errout_str()); } void nullpointer74() { @@ -2383,7 +2384,7 @@ class TestNullPointer : public TestFixture { " } while (i > 0);\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:8] -> [test.cpp:7]: (warning) Either the condition 'f' is redundant or there is possible null pointer dereference: f.\n", + "[test.cpp:8:9] -> [test.cpp:7:9]: (warning) Either the condition 'f' is redundant or there is possible null pointer dereference: f. [nullPointerRedundantCheck]\n", errout_str()); check("struct d {\n" @@ -2462,7 +2463,7 @@ class TestNullPointer : public TestFixture { " pp = &p;\n" " **pp = 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Null pointer dereference: *pp\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:6]: (error) Null pointer dereference: *pp [nullPointer]\n", errout_str()); } void nullpointer79() // #10400 @@ -2540,7 +2541,7 @@ class TestNullPointer : public TestFixture { " *p = 1;\n" " return x;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (warning) Possible null pointer dereference: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:4]: (warning) Possible null pointer dereference: p [nullPointer]\n", errout_str()); } void nullpointer84() // #9873 @@ -2552,7 +2553,7 @@ class TestNullPointer : public TestFixture { " }\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition '!RP' is redundant or there is possible null pointer dereference: P.\n", + "[test.cpp:3:7] -> [test.cpp:4:5]: (warning) Either the condition '!RP' is redundant or there is possible null pointer dereference: P. [nullPointerRedundantCheck]\n", errout_str()); } @@ -2573,7 +2574,7 @@ class TestNullPointer : public TestFixture { " return s.GetId();\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:5] -> [test.cpp:4]: (warning) Either the condition 'm_notebook' is redundant or there is possible null pointer dereference: m_notebook.\n", + "[test.cpp:5:11] -> [test.cpp:4:18]: (warning) Either the condition 'm_notebook' is redundant or there is possible null pointer dereference: m_notebook. [nullPointerRedundantCheck]\n", errout_str()); } @@ -2608,7 +2609,7 @@ class TestNullPointer : public TestFixture { " else\n" " return *x + 1;\n" "}\n"); - TODO_ASSERT_EQUALS("", "[test.cpp:6] -> [test.cpp:9]: (warning) Either the condition 'x!=nullptr' is redundant or there is possible null pointer dereference: x.\n", errout_str()); + TODO_ASSERT_EQUALS("", "[test.cpp:6:22] -> [test.cpp:9:17]: (warning) Either the condition 'x!=nullptr' is redundant or there is possible null pointer dereference: x. [nullPointerRedundantCheck]\n", errout_str()); check("void f(int n, int* p) {\n" " int* r = nullptr;\n" @@ -2657,7 +2658,7 @@ class TestNullPointer : public TestFixture { " if(ptr->y != nullptr) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:9] -> [test.cpp:8]: (warning) Either the condition 'ptr->y!=nullptr' is redundant or there is possible null pointer dereference: ptr->y.\n", + "[test.cpp:9:19] -> [test.cpp:8:11]: (warning) Either the condition 'ptr->y!=nullptr' is redundant or there is possible null pointer dereference: ptr->y. [nullPointerRedundantCheck]\n", errout_str()); check("bool argsMatch(const Token *first, const Token *second) {\n" // #6145 @@ -2676,8 +2677,8 @@ class TestNullPointer : public TestFixture { " return false;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:10] -> [test.cpp:2]: (warning) Either the condition '!first' is redundant or there is possible null pointer dereference: first.\n" - "[test.cpp:10] -> [test.cpp:4]: (warning) Either the condition '!first' is redundant or there is possible null pointer dereference: first.\n", + "[test.cpp:10:13] -> [test.cpp:2:9]: (warning) Either the condition '!first' is redundant or there is possible null pointer dereference: first. [nullPointerRedundantCheck]\n" + "[test.cpp:10:13] -> [test.cpp:4:14]: (warning) Either the condition '!first' is redundant or there is possible null pointer dereference: first. [nullPointerRedundantCheck]\n", errout_str()); } @@ -2699,7 +2700,7 @@ class TestNullPointer : public TestFixture { " return \"unknown\";\n" "}"); ASSERT_EQUALS( - "[test.cpp:7] -> [test.cpp:3]: (warning) Either the condition 'ctx' is redundant or there is possible null pointer dereference: ctx.\n", + "[test.cpp:7:12] -> [test.cpp:3:7]: (warning) Either the condition 'ctx' is redundant or there is possible null pointer dereference: ctx. [nullPointerRedundantCheck]\n", errout_str()); } @@ -2740,7 +2741,7 @@ class TestNullPointer : public TestFixture { " *myNull=42;\n" " return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: myNull\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (error) Null pointer dereference: myNull [nullPointer]\n", errout_str()); check("struct foo {\n" " int* GetThing(void) { return 0; }\n" @@ -2751,7 +2752,7 @@ class TestNullPointer : public TestFixture { " *myNull=42;\n" " return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Null pointer dereference: myNull\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:10]: (error) Null pointer dereference: myNull [nullPointer]\n", errout_str()); check("struct T { bool g() const; };\n" "void f(T* p) {\n" @@ -2760,7 +2761,7 @@ class TestNullPointer : public TestFixture { " while (p->g())\n" " p = nullptr;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Possible null pointer dereference: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (warning) Possible null pointer dereference: p [nullPointer]\n", errout_str()); } void nullpointer94() // #11040 @@ -2773,7 +2774,7 @@ class TestNullPointer : public TestFixture { " (*kep)->next = 0;\n" " (*kep)->len = slen;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (warning) If memory allocation fails, then there is a possible null pointer dereference: *kep\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:6]: (warning) If memory allocation fails, then there is a possible null pointer dereference: *kep [nullPointerOutOfMemory]\n", errout_str()); } void nullpointer95() // #11142 @@ -2848,7 +2849,7 @@ class TestNullPointer : public TestFixture { " buf[2] = 0;" // << " }\n" "}"); - ASSERT_EQUALS("[test.cpp:14]: (error) Null pointer dereference: buf\n", errout_str()); + ASSERT_EQUALS("[test.cpp:14:9]: (error) Null pointer dereference: buf [nullPointer]\n", errout_str()); } void nullpointer100() // #11636 @@ -2915,7 +2916,7 @@ class TestNullPointer : public TestFixture { " int x = -2;\n" " f(nullptr, &x);\n" "}\n"); - TODO_ASSERT_EQUALS("", "[test.cpp:3]: (warning) Possible null pointer dereference: p\n", errout_str()); + TODO_ASSERT_EQUALS("", "[test.cpp:3:10]: (warning) Possible null pointer dereference: p [nullPointer]\n", errout_str()); } void nullpointer_addressOf() { // address of @@ -2955,7 +2956,7 @@ class TestNullPointer : public TestFixture { " }\n" " return p;\n" "}", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:7]: (warning) Possible null pointer dereference: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:10]: (warning) Possible null pointer dereference: p [nullPointer]\n", errout_str()); } void nullpointer_cast() { @@ -3002,27 +3003,27 @@ class TestNullPointer : public TestFixture { " }\n" " *p = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:4:6]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(char *p) {\n" " if (p && *p == 0) {\n" " }\n" " printf(\"%c\", *p);\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:4:19]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(char *p) {\n" " if (p && *p == 0) {\n" " } else { *p = 0; }\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:15]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(char *p) {\n" " if (p) {\n" " }\n" " strcpy(p, \"abc\");\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:4:12]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(char *p) {\n" " if (p) {\n" @@ -3030,7 +3031,7 @@ class TestNullPointer : public TestFixture { " bar();\n" " strcpy(p, \"abc\");\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:5:12]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(abc *p) {\n" " if (!p) {\n" @@ -3099,8 +3100,8 @@ class TestNullPointer : public TestFixture { " return 5+*p;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p.\n" - "[test.cpp:2] -> [test.cpp:4]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:14]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n" + "[test.cpp:2:9] -> [test.cpp:4:19]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); // operator! check("void f() {\n" @@ -3136,7 +3137,7 @@ class TestNullPointer : public TestFixture { " }\n" " *p = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:5:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); // #2467 - unknown macro may terminate the application check("void f(Fred *fred) {\n" @@ -3236,7 +3237,7 @@ class TestNullPointer : public TestFixture { " if (fred) { }\n" " return fred->a;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition 'fred' is redundant or there is possible null pointer dereference: fred.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Either the condition 'fred' is redundant or there is possible null pointer dereference: fred. [nullPointerRedundantCheck]\n", errout_str()); // #2789 - assign and check pointer check("void f() {\n" @@ -3244,7 +3245,7 @@ class TestNullPointer : public TestFixture { " if (!p) { }\n" " *p = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:4:6]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); // check, assign and use check("void f() {\n" @@ -3271,7 +3272,7 @@ class TestNullPointer : public TestFixture { " return;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:3:21]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); // check, and use check("void f() {\n" @@ -3280,7 +3281,7 @@ class TestNullPointer : public TestFixture { " return;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:3:19]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); // check, and use check("void f() {\n" @@ -3298,7 +3299,7 @@ class TestNullPointer : public TestFixture { " return;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (warning) Either the condition 'p==NULL' is redundant or there is possible null pointer dereference: p.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:3:24]: (warning) Either the condition 'p==NULL' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); // check, and use check("void f(struct X *p, int x) {\n" @@ -3315,7 +3316,7 @@ class TestNullPointer : public TestFixture { "}"; check(code); // inconclusive - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition 'fred==NULL' is redundant or there is possible null pointer dereference: fred.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14] -> [test.cpp:3:5]: (warning) Either the condition 'fred==NULL' is redundant or there is possible null pointer dereference: fred. [nullPointerRedundantCheck]\n", errout_str()); } check("void f(char *s) {\n" // #3358 @@ -3360,7 +3361,7 @@ class TestNullPointer : public TestFixture { " if (x || !p) {}\n" " *p = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14] -> [test.cpp:3:6]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); // sizeof check("void f() {\n" @@ -3376,7 +3377,7 @@ class TestNullPointer : public TestFixture { " int* p = 0;\n" " return p[4];\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); check("void f() {\n" " typeof(*NULL) y;\n" @@ -3389,7 +3390,7 @@ class TestNullPointer : public TestFixture { "int main() {\n" " return *f();\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference: f()\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (error) Null pointer dereference: f() [nullPointer]\n", errout_str()); } void gcc_statement_expression() { @@ -3413,14 +3414,14 @@ class TestNullPointer : public TestFixture { check("void f() {\n" " int bytes = snprintf(0, 10, \"%u\", 1);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:26]: (error) Null pointer dereference [nullPointer]\n", errout_str()); } void printf_with_invalid_va_argument() { check("void f() {\n" " printf(\"%s\", 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (error) Null pointer dereference [nullPointer]\n", errout_str()); check("void f(char* s) {\n" " printf(\"%s\", s);\n" @@ -3432,8 +3433,8 @@ class TestNullPointer : public TestFixture { " printf(\"%s\", s);\n" "}"); ASSERT_EQUALS( - "[test.cpp:3]: (error) Null pointer dereference: s\n" - "[test.cpp:3]: (error) Null pointer dereference\n", + "[test.cpp:3:18]: (error) Null pointer dereference: s [nullPointer]\n" + "[test.cpp:3:18]: (error) Null pointer dereference [nullPointer]\n", errout_str()); check("void f() {\n" @@ -3445,7 +3446,7 @@ class TestNullPointer : public TestFixture { check("void f() {\n" " printf(\"%u%s\", 0, 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:23]: (error) Null pointer dereference [nullPointer]\n", errout_str()); check("void f(char* s) {\n" " printf(\"%u%s\", 0, s);\n" @@ -3457,20 +3458,20 @@ class TestNullPointer : public TestFixture { " printf(\"%u%s\", 123, s);\n" "}"); ASSERT_EQUALS( - "[test.cpp:3]: (error) Null pointer dereference: s\n" - "[test.cpp:3]: (error) Null pointer dereference\n", + "[test.cpp:3:25]: (error) Null pointer dereference: s [nullPointer]\n" + "[test.cpp:3:25]: (error) Null pointer dereference [nullPointer]\n", errout_str()); check("void f() {\n" " printf(\"%%%s%%\", 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:22]: (error) Null pointer dereference [nullPointer]\n", errout_str()); check("void f(char* s) {\n" " printf(\"text: %s, %s\", s, 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:31]: (error) Null pointer dereference [nullPointer]\n", errout_str()); check("void f() {\n" @@ -3483,12 +3484,12 @@ class TestNullPointer : public TestFixture { check("void f(char* s) {\n" " printf(\"text: %m%s, %s\", s, 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:33]: (error) Null pointer dereference [nullPointer]\n", errout_str()); check("void f(char* s) {\n" " printf(\"text: %*s, %s\", s, 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:32]: (error) Null pointer dereference [nullPointer]\n", errout_str()); // Ticket #3364 check("void f() {\n" @@ -3503,16 +3504,16 @@ class TestNullPointer : public TestFixture { " sscanf(s, \"%s\", 0);\n" "}"); ASSERT_EQUALS( - "[test.cpp:2]: (error) Null pointer dereference\n" - "[test.cpp:2]: (error) Null pointer dereference\n", // duplicate + "[test.cpp:2:21]: (error) Null pointer dereference [nullPointer]\n" + "[test.cpp:2:21]: (error) Null pointer dereference [nullPointer]\n", // duplicate errout_str()); check("void f() {\n" " scanf(\"%d\", 0);\n" "}"); ASSERT_EQUALS( - "[test.cpp:2]: (error) Null pointer dereference\n" - "[test.cpp:2]: (error) Null pointer dereference\n", // duplicate + "[test.cpp:2:17]: (error) Null pointer dereference [nullPointer]\n" + "[test.cpp:2:17]: (error) Null pointer dereference [nullPointer]\n", // duplicate errout_str()); check("void f(char* foo) {\n" @@ -3533,9 +3534,9 @@ class TestNullPointer : public TestFixture { " sscanf(dummy, \"%d\", iVal);\n" "}"); ASSERT_EQUALS( - "[test.cpp:3]: (error) Null pointer dereference: iVal\n" - "[test.cpp:3]: (error) Null pointer dereference\n" - "[test.cpp:3]: (error) Null pointer dereference\n", // duplicate + "[test.cpp:3:25]: (error) Null pointer dereference: iVal [nullPointer]\n" + "[test.cpp:3:25]: (error) Null pointer dereference [nullPointer]\n" + "[test.cpp:3:25]: (error) Null pointer dereference [nullPointer]\n", // duplicate errout_str()); check("void f(char *dummy) {\n" @@ -3554,8 +3555,8 @@ class TestNullPointer : public TestFixture { " sscanf(dummy, \"%*d%u\", 0);\n" "}"); ASSERT_EQUALS( - "[test.cpp:2]: (error) Null pointer dereference\n" - "[test.cpp:2]: (error) Null pointer dereference\n", // duplicate + "[test.cpp:2:28]: (error) Null pointer dereference [nullPointer]\n" + "[test.cpp:2:28]: (error) Null pointer dereference [nullPointer]\n", // duplicate errout_str()); } @@ -3566,7 +3567,7 @@ class TestNullPointer : public TestFixture { " if(maybe()) iVal = g();\n" " return iVal[0];\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Possible null pointer dereference: iVal\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (warning) Possible null pointer dereference: iVal [nullPointer]\n", errout_str()); check("int foo(int* iVal) {\n" " return iVal[0];\n" @@ -3755,14 +3756,14 @@ class TestNullPointer : public TestFixture { " std::string s5(p);\n" " foo(std::string(p));\n" "}", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:9]: (error) Null pointer dereference: p\n" - "[test.cpp:10]: (error) Null pointer dereference: p\n" - "[test.cpp:11]: (error) Null pointer dereference: p\n" - "[test.cpp:12]: (error) Null pointer dereference: p\n" - "[test.cpp:3]: (error) Null pointer dereference\n" - "[test.cpp:5]: (error) Null pointer dereference\n" - "[test.cpp:7]: (error) Null pointer dereference\n" - "[test.cpp:8]: (error) Null pointer dereference\n" + ASSERT_EQUALS("[test.cpp:9:10]: (error) Null pointer dereference: p [nullPointer]\n" + "[test.cpp:10:22]: (error) Null pointer dereference: p [nullPointer]\n" + "[test.cpp:11:20]: (error) Null pointer dereference: p [nullPointer]\n" + "[test.cpp:12:21]: (error) Null pointer dereference: p [nullPointer]\n" + "[test.cpp:3:10]: (error) Null pointer dereference [nullPointer]\n" + "[test.cpp:5:22]: (error) Null pointer dereference [nullPointer]\n" + "[test.cpp:7:17]: (error) Null pointer dereference [nullPointer]\n" + "[test.cpp:8:9]: (error) Null pointer dereference [nullPointer]\n" , errout_str()); check("void f(std::string s1) {\n" @@ -3771,10 +3772,10 @@ class TestNullPointer : public TestFixture { " std::string s3(nullptr);\n" " foo(std::string(nullptr));\n" "}", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference\n" - "[test.cpp:3]: (error) Null pointer dereference\n" - "[test.cpp:4]: (error) Null pointer dereference\n" - "[test.cpp:5]: (error) Null pointer dereference\n" + ASSERT_EQUALS("[test.cpp:2:10]: (error) Null pointer dereference [nullPointer]\n" + "[test.cpp:3:22]: (error) Null pointer dereference [nullPointer]\n" + "[test.cpp:4:17]: (error) Null pointer dereference [nullPointer]\n" + "[test.cpp:5:9]: (error) Null pointer dereference [nullPointer]\n" , errout_str()); check("void f(std::string s1) {\n" @@ -3783,10 +3784,10 @@ class TestNullPointer : public TestFixture { " std::string s3(NULL);\n" " foo(std::string(NULL));\n" "}", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference\n" - "[test.cpp:3]: (error) Null pointer dereference\n" - "[test.cpp:4]: (error) Null pointer dereference\n" - "[test.cpp:5]: (error) Null pointer dereference\n" + ASSERT_EQUALS("[test.cpp:2:10]: (error) Null pointer dereference [nullPointer]\n" + "[test.cpp:3:22]: (error) Null pointer dereference [nullPointer]\n" + "[test.cpp:4:17]: (error) Null pointer dereference [nullPointer]\n" + "[test.cpp:5:9]: (error) Null pointer dereference [nullPointer]\n" , errout_str()); check("void f(std::string s1, const std::string& s2, const std::string* s3) {\n" @@ -3799,10 +3800,10 @@ class TestNullPointer : public TestFixture { " foo(p == s2);\n" " foo(p == s3);\n" "}", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n" - "[test.cpp:5]: (error) Null pointer dereference: p\n" - "[test.cpp:7]: (error) Null pointer dereference: p\n" - "[test.cpp:8]: (error) Null pointer dereference: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:15]: (error) Null pointer dereference: p [nullPointer]\n" + "[test.cpp:5:15]: (error) Null pointer dereference: p [nullPointer]\n" + "[test.cpp:7:9]: (error) Null pointer dereference: p [nullPointer]\n" + "[test.cpp:8:9]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); check("void f(std::string s1, const std::string& s2, const std::string* s3) {\n" " void* p = 0;\n" @@ -3843,8 +3844,8 @@ class TestNullPointer : public TestFixture { " Foo();\n" "};\n" "Foo::Foo() : s(0) {}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference\n" - "[test.cpp:9]: (error) Null pointer dereference\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (error) Null pointer dereference [nullPointer]\n" + "[test.cpp:9:14]: (error) Null pointer dereference [nullPointer]\n", errout_str()); check("void f() {\n" " std::string s = 0 == x ? \"a\" : \"b\";\n" @@ -3866,10 +3867,10 @@ class TestNullPointer : public TestFixture { " foo(var, nullptr);\n" " foo(0, var);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference\n" - "[test.cpp:5]: (error) Null pointer dereference\n" - "[test.cpp:6]: (error) Null pointer dereference\n" - "[test.cpp:7]: (error) Null pointer dereference\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (error) Null pointer dereference [nullPointer]\n" + "[test.cpp:5:12]: (error) Null pointer dereference [nullPointer]\n" + "[test.cpp:6:12]: (error) Null pointer dereference [nullPointer]\n" + "[test.cpp:7:12]: (error) Null pointer dereference [nullPointer]\n", errout_str()); check("std::string f() {\n" // #9827 " char* p = NULL;\n" @@ -3886,13 +3887,13 @@ class TestNullPointer : public TestFixture { " std::string s1{ p };\n" " std::string s2{ nullptr };\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference: p\n" - "[test.cpp:4]: (error) Null pointer dereference\n", + ASSERT_EQUALS("[test.cpp:3:21]: (error) Null pointer dereference: p [nullPointer]\n" + "[test.cpp:4:17]: (error) Null pointer dereference [nullPointer]\n", errout_str()); check("const char* g(long) { return nullptr; }\n" // #11561 "void f() { std::string s = g(0L); }\n"); - ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference: g(0L)\n", + ASSERT_EQUALS("[test.cpp:2:29]: (error) Null pointer dereference: g(0L) [nullPointer]\n", errout_str()); } @@ -3910,9 +3911,9 @@ class TestNullPointer : public TestFixture { " if(q == 0)\n" " oss << foo << q;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference: p\n" - "[test.cpp:4]: (error) Null pointer dereference: p\n" - "[test.cpp:5] -> [test.cpp:6]: (warning) Either the condition 'q==0' is redundant or there is possible null pointer dereference: q.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (error) Null pointer dereference: p [nullPointer]\n" + "[test.cpp:4:19]: (error) Null pointer dereference: p [nullPointer]\n" + "[test.cpp:5:10] -> [test.cpp:6:23]: (warning) Either the condition 'q==0' is redundant or there is possible null pointer dereference: q. [nullPointerRedundantCheck]\n", errout_str()); check("void f(const char* p) {\n" " if(p == 0) {\n" @@ -3922,12 +3923,12 @@ class TestNullPointer : public TestFixture { " std::cout << abc << p;\n" " }\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p.\n" - "[test.cpp:2] -> [test.cpp:4]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p.\n" - "[test.cpp:2] -> [test.cpp:5]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p.\n" - "[test.cpp:2] -> [test.cpp:6]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p.\n", - "[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p.\n" - "[test.cpp:2] -> [test.cpp:4]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p.\n", + TODO_ASSERT_EQUALS("[test.cpp:2:10] -> [test.cpp:3:22]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n" + "[test.cpp:2:10] -> [test.cpp:4:22]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n" + "[test.cpp:2:10] -> [test.cpp:5]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n" + "[test.cpp:2:10] -> [test.cpp:6]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", + "[test.cpp:2:10] -> [test.cpp:3:22]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n" + "[test.cpp:2:10] -> [test.cpp:4:22]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("void f() {\n" @@ -3980,42 +3981,42 @@ class TestNullPointer : public TestFixture { " if (p) {}\n" " dostuff(p->x);\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:7] -> [test.cpp:4:11]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("struct Fred { int x; };\n" "void f(std::shared_ptr p) {\n" " p = nullptr;\n" " dostuff(p->x);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); check("struct Fred { int x; };\n" "void f(std::unique_ptr p) {\n" " if (p) {}\n" " dostuff(p->x);\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:7] -> [test.cpp:4:11]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("struct Fred { int x; };\n" "void f(std::unique_ptr p) {\n" " p = nullptr;\n" " dostuff(p->x);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); check("struct Fred { int x; };\n" "void f() {\n" " std::shared_ptr p;\n" " dostuff(p->x);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); check("struct Fred { int x; };\n" "void f(std::shared_ptr p) {\n" " p.reset();\n" " dostuff(p->x);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); check("struct Fred { int x; };\n" "void f(std::shared_ptr p) {\n" @@ -4023,7 +4024,7 @@ class TestNullPointer : public TestFixture { " p.reset(pp);\n" " dostuff(p->x);\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:11]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); check("struct Fred { int x; };\n" "void f(Fred& f) {\n" @@ -4038,14 +4039,14 @@ class TestNullPointer : public TestFixture { " p.reset();\n" " dostuff(p->x);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); check("struct Fred { int x; };\n" "void f() {\n" " std::shared_ptr p(nullptr);\n" " dostuff(p->x);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); check("struct A {};\n" "void f(int n) {\n" @@ -4082,7 +4083,7 @@ class TestNullPointer : public TestFixture { " int a = *f();\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference: f()\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:15]: (error) Null pointer dereference: f() [nullPointer]\n", errout_str()); } void nullpointerOutOfMemory() { @@ -4091,21 +4092,21 @@ class TestNullPointer : public TestFixture { " *p = 0;\n" " free(p);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) If memory allocation fails, then there is a possible null pointer dereference: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: (warning) If memory allocation fails, then there is a possible null pointer dereference: p [nullPointerOutOfMemory]\n", errout_str()); check("void f() {\n" " int *p = malloc(10);\n" " *(p+2) = 0;\n" " free(p);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) If memory allocation fails: pointer addition with NULL pointer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8]: (error) If memory allocation fails: pointer addition with NULL pointer. [nullPointerArithmeticOutOfMemory]\n", errout_str()); check("void f() {\n" // #13676 " int* q = static_cast(std::malloc(4));\n" " *q = 0;\n" " std::free(q);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) If memory allocation fails, then there is a possible null pointer dereference: q\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: (warning) If memory allocation fails, then there is a possible null pointer dereference: q [nullPointerOutOfMemory]\n", errout_str()); } void functioncall() { // #3443 - function calls @@ -4128,7 +4129,7 @@ class TestNullPointer : public TestFixture { " if (p) { }\n" "}"); ASSERT_EQUALS( - "[test.cpp:6] -> [test.cpp:4]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p.\n", + "[test.cpp:6:9] -> [test.cpp:4:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); // function seen (taking reference parameter) @@ -4150,7 +4151,7 @@ class TestNullPointer : public TestFixture { " if (p) { }\n" "}"); ASSERT_EQUALS( - "[test.cpp:6] -> [test.cpp:4]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p.\n", + "[test.cpp:6:9] -> [test.cpp:4:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); // inconclusive @@ -4160,7 +4161,7 @@ class TestNullPointer : public TestFixture { " if (p) { }\n" "}", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:2]: (warning, inconclusive) Either the condition 'p' is redundant or there is possible null pointer dereference: p.\n", + "[test.cpp:4:9] -> [test.cpp:2:6]: (warning, inconclusive) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); } @@ -4183,7 +4184,7 @@ class TestNullPointer : public TestFixture { " if (abc) { }\n" "}"); ASSERT_EQUALS( - "[test.cpp:6] -> [test.cpp:4]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc.\n", + "[test.cpp:6:9] -> [test.cpp:4:5]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n", errout_str()); // function implementation not seen @@ -4195,7 +4196,7 @@ class TestNullPointer : public TestFixture { " if (abc) { }\n" "}"); ASSERT_EQUALS( - "[test.cpp:6] -> [test.cpp:4]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc.\n", + "[test.cpp:6:9] -> [test.cpp:4:5]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n", errout_str()); // inconclusive @@ -4205,7 +4206,7 @@ class TestNullPointer : public TestFixture { " if (abc) { }\n" "}", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:2]: (warning, inconclusive) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc.\n", + "[test.cpp:4:9] -> [test.cpp:2:5]: (warning, inconclusive) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n", errout_str()); } } @@ -4261,7 +4262,7 @@ class TestNullPointer : public TestFixture { check("void f(int *p = 0) {\n" " *p = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Possible null pointer dereference if the default parameter value is used: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:6]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\n", errout_str()); check("void f(int *p = 0) {\n" " if (!p)\n" @@ -4273,17 +4274,17 @@ class TestNullPointer : public TestFixture { check("void f(char a, int *p = 0) {\n" " *p = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Possible null pointer dereference if the default parameter value is used: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:6]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\n", errout_str()); check("void f(int *p = 0) {\n" " printf(\"p = %d\", *p);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Possible null pointer dereference if the default parameter value is used: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:23]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\n", errout_str()); check("void f(int *p = 0) {\n" " printf(\"p[1] = %d\", p[1]);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Possible null pointer dereference if the default parameter value is used: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:25]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\n", errout_str()); check("void f(int *p = 0) {\n" " buf[p] = 0;\n" @@ -4320,7 +4321,7 @@ class TestNullPointer : public TestFixture { " *p = 0;\n" "}", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( - "[test.cpp:3]: (warning) Possible null pointer dereference if the default parameter value is used: p\n", + "[test.cpp:3:8]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\n", errout_str()); check("void f(int *p = 0) {\n" @@ -4346,14 +4347,14 @@ class TestNullPointer : public TestFixture { check("void f(int *p = 0) {\n" " std::cout << p ? *p : 0;\n" // Due to operator precedence, this is equivalent to: (std::cout << p) ? *p : 0; "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Possible null pointer dereference if the default parameter value is used: p\n", errout_str()); // Check the first branch of ternary + ASSERT_EQUALS("[test.cpp:2:23]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\n", errout_str()); // Check the first branch of ternary check("void f(char *p = 0) {\n" " std::cout << p ? *p : 0;\n" // Due to operator precedence, this is equivalent to: (std::cout << p) ? *p : 0; "}"); ASSERT_EQUALS( - "[test.cpp:2]: (warning) Possible null pointer dereference if the default parameter value is used: p\n" - "[test.cpp:2]: (warning) Possible null pointer dereference if the default parameter value is used: p\n", // duplicate + "[test.cpp:2:18]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\n" + "[test.cpp:2:23]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\n", // duplicate errout_str()); check("void f(int *p = 0) {\n" @@ -4394,7 +4395,7 @@ class TestNullPointer : public TestFixture { " printf(\"%p\", p);\n" " *p = 0;\n" "}", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (warning) Possible null pointer dereference if the default parameter value is used: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\n", errout_str()); // The init() function may or may not initialize p, but since the address // of p is passed in, it's a good bet that p may be modified and @@ -4431,11 +4432,11 @@ class TestNullPointer : public TestFixture { check("void foo(int x, int *p = 0) {\n" " int var1 = x ? *p : 5;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Possible null pointer dereference if the default parameter value is used: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:21]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\n", errout_str()); check("void f(int* i = nullptr) { *i = 0; }\n" // #11567 "void g() { f(); }\n"); - ASSERT_EQUALS("[test.cpp:1]: (warning) Possible null pointer dereference if the default parameter value is used: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:29]: (warning) Possible null pointer dereference if the default parameter value is used: i [nullPointerDefaultArg]\n", errout_str()); } void nullpointer_internal_error() { // ticket #5080 @@ -4470,33 +4471,33 @@ class TestNullPointer : public TestFixture { " char *p = s - 20;\n" "}\n" "void bar() { foo(0); }"); - ASSERT_EQUALS("[test.cpp:2]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted.\n", + ASSERT_EQUALS("[test.cpp:2:15]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted. [nullPointerArithmetic]\n", errout_str()); check("void foo(char *s) {\n" " if (!s) {}\n" " char *p = s - 20;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition '!s' is redundant or there is overflow in pointer subtraction.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:7] -> [test.cpp:3:15]: (warning) Either the condition '!s' is redundant or there is overflow in pointer subtraction. [nullPointerArithmeticRedundantCheck]\n", errout_str()); check("void foo(char *s) {\n" " s -= 20;\n" "}\n" "void bar() { foo(0); }"); - ASSERT_EQUALS("[test.cpp:2]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted.\n", + ASSERT_EQUALS("[test.cpp:2:5]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted. [nullPointerArithmetic]\n", errout_str()); check("void foo(char *s) {\n" " if (!s) {}\n" " s -= 20;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition '!s' is redundant or there is overflow in pointer subtraction.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:7] -> [test.cpp:3:5]: (warning) Either the condition '!s' is redundant or there is overflow in pointer subtraction. [nullPointerArithmeticRedundantCheck]\n", errout_str()); check("int* f8() { int *x = NULL; return --x; }"); - ASSERT_EQUALS("[test.cpp:1]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:35]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted. [nullPointerArithmetic]\n", errout_str()); check("int* f9() { int *x = NULL; return x--; }"); - ASSERT_EQUALS("[test.cpp:1]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:36]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted. [nullPointerArithmetic]\n", errout_str()); } void addNull() { @@ -4504,43 +4505,43 @@ class TestNullPointer : public TestFixture { " char * p = s + 20;\n" "}\n" "void bar() { foo(0); }"); - ASSERT_EQUALS("[test.cpp:2]: (error) Pointer addition with NULL pointer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\n", errout_str()); check("void foo(char *s) {\n" " if (!s) {}\n" " char * p = s + 20;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition '!s' is redundant or there is pointer arithmetic with NULL pointer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:7] -> [test.cpp:3:16]: (warning) Either the condition '!s' is redundant or there is pointer arithmetic with NULL pointer. [nullPointerArithmeticRedundantCheck]\n", errout_str()); check("void foo(char *s) {\n" " char * p = 20 + s;\n" "}\n" "void bar() { foo(0); }"); - ASSERT_EQUALS("[test.cpp:2]: (error) Pointer addition with NULL pointer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\n", errout_str()); check("void foo(char *s) {\n" " if (!s) {}\n" " char * p = 20 + s;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition '!s' is redundant or there is pointer arithmetic with NULL pointer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:7] -> [test.cpp:3:17]: (warning) Either the condition '!s' is redundant or there is pointer arithmetic with NULL pointer. [nullPointerArithmeticRedundantCheck]\n", errout_str()); check("void foo(char *s) {\n" " s += 20;\n" "}\n" "void bar() { foo(0); }"); - ASSERT_EQUALS("[test.cpp:2]: (error) Pointer addition with NULL pointer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\n", errout_str()); check("void foo(char *s) {\n" " if (!s) {}\n" " s += 20;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition '!s' is redundant or there is pointer arithmetic with NULL pointer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:7] -> [test.cpp:3:5]: (warning) Either the condition '!s' is redundant or there is pointer arithmetic with NULL pointer. [nullPointerArithmeticRedundantCheck]\n", errout_str()); check("int* f7() { int *x = NULL; return ++x; }"); - ASSERT_EQUALS("[test.cpp:1]: (error) Pointer addition with NULL pointer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:35]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\n", errout_str()); check("int* f10() { int *x = NULL; return x++; }"); - ASSERT_EQUALS("[test.cpp:1]: (error) Pointer addition with NULL pointer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:37]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\n", errout_str()); check("class foo {};\n" "const char* get() const { return 0; }\n" diff --git a/test/testtype.cpp b/test/testtype.cpp index d026cb0095d..dde8397e1a5 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -37,6 +37,7 @@ class TestType : public TestFixture { void run() override { TEST_CASE(checkTooBigShift_Unix32); + mNewTemplate = true; TEST_CASE(checkIntegerOverflow); TEST_CASE(signConversion); TEST_CASE(longCastAssign); @@ -274,16 +275,16 @@ class TestType : public TestFixture { const Settings settings = settingsBuilder().severity(Severity::warning).platform(Platform::Type::Unix32).build(); check("x = (int)0x10000 * (int)0x10000;", settings); - ASSERT_EQUALS("[test.cpp:1]: (error) Signed integer overflow for expression '(int)0x10000*(int)0x10000'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:18]: (error) Signed integer overflow for expression '(int)0x10000*(int)0x10000'. [integerOverflow]\n", errout_str()); check("x = (long)0x10000 * (long)0x10000;", settings); - ASSERT_EQUALS("[test.cpp:1]: (error) Signed integer overflow for expression '(long)0x10000*(long)0x10000'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:19]: (error) Signed integer overflow for expression '(long)0x10000*(long)0x10000'. [integerOverflow]\n", errout_str()); check("void foo() {\n" " int intmax = 0x7fffffff;\n" " return intmax + 1;\n" "}",settings); - ASSERT_EQUALS("[test.cpp:3]: (error) Signed integer overflow for expression 'intmax+1'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (error) Signed integer overflow for expression 'intmax+1'. [integerOverflow]\n", errout_str()); check("void foo() {\n" " int intmax = 0x7fffffff;\n" @@ -295,13 +296,13 @@ class TestType : public TestFixture { " if (x==123456) {}\n" " return x * x;\n" "}",settings); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition 'x==123456' is redundant or there is signed integer overflow for expression 'x*x'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Either the condition 'x==123456' is redundant or there is signed integer overflow for expression 'x*x'. [integerOverflowCond]\n", errout_str()); check("int foo(signed int x) {\n" " if (x==123456) {}\n" " return -123456 * x;\n" "}",settings); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition 'x==123456' is redundant or there is signed integer underflow for expression '-123456*x'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:19]: (warning) Either the condition 'x==123456' is redundant or there is signed integer underflow for expression '-123456*x'. [integerOverflowCond]\n", errout_str()); check("int foo(signed int x) {\n" " if (x==123456) {}\n" @@ -312,7 +313,7 @@ class TestType : public TestFixture { check("int f(int i) {\n" // #12117 " return (i == 31) ? 1 << i : 0;\n" "}", settings); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (warning) Shifting signed 32-bit value by 31 bits is undefined behaviour. See condition at line 2.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15] -> [test.cpp:2:26]: (warning) Shifting signed 32-bit value by 31 bits is undefined behaviour. See condition at line 2. [shiftTooManyBitsSigned]\n", errout_str()); check("void f() {\n" // #13092 " int n = 0;\n" @@ -320,31 +321,31 @@ class TestType : public TestFixture { " n = n * 47163 - 57412;\n" " }\n" "}", settings); - ASSERT_EQUALS("[test.cpp:4]: (error) Signed integer underflow for expression 'n*47163'.\n" - "[test.cpp:4]: (error) Signed integer underflow for expression 'n*47163-57412'.\n", + ASSERT_EQUALS("[test.cpp:4:15]: (error) Signed integer underflow for expression 'n*47163'. [integerOverflow]\n" + "[test.cpp:4:23]: (error) Signed integer underflow for expression 'n*47163-57412'. [integerOverflow]\n", errout_str()); } void signConversion() { const Settings settings = settingsBuilder().platform(Platform::Type::Unix64).build(); check("x = -4 * (unsigned)y;", settingsDefault); - ASSERT_EQUALS("[test.cpp:1]: (warning) Expression '-4' has a negative value. That is converted to an unsigned value and used in an unsigned calculation.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:6]: (warning) Expression '-4' has a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversion]\n", errout_str()); check("x = (unsigned)y * -4;", settingsDefault); - ASSERT_EQUALS("[test.cpp:1]: (warning) Expression '-4' has a negative value. That is converted to an unsigned value and used in an unsigned calculation.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:20]: (warning) Expression '-4' has a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversion]\n", errout_str()); check("unsigned int dostuff(int x) {\n" // x is signed " if (x==0) {}\n" " return (x-1)*sizeof(int);\n" "}", settings); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Expression 'x-1' can have a negative value. That is converted to an unsigned value and used in an unsigned calculation.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:8] -> [test.cpp:3:12]: (warning) Expression 'x-1' can have a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversionCond]\n", errout_str()); check("unsigned int f1(signed int x, unsigned int y) {" // x is signed " return x * y;\n" "}\n" "void f2() { f1(-4,4); }", settingsDefault); ASSERT_EQUALS( - "[test.cpp:1]: (warning) Expression 'x' can have a negative value. That is converted to an unsigned value and used in an unsigned calculation.\n", + "[test.cpp:1:57]: (warning) Expression 'x' can have a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversion]\n", errout_str()); check("unsigned int f1(int x) {" @@ -352,7 +353,7 @@ class TestType : public TestFixture { "}\n" "void f2() { f1(-4); }", settingsDefault); ASSERT_EQUALS( - "[test.cpp:1]: (warning) Expression 'x' can have a negative value. That is converted to an unsigned value and used in an unsigned calculation.\n", + "[test.cpp:1:34]: (warning) Expression 'x' can have a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversion]\n", errout_str()); check("unsigned int f1(int x) {" // #6168: FP for inner calculation @@ -371,7 +372,7 @@ class TestType : public TestFixture { check("size_t foo(size_t x) {\n" " return -2 * x;\n" "}", settingsDefault); - ASSERT_EQUALS("[test.cpp:2]: (warning) Expression '-2' has a negative value. That is converted to an unsigned value and used in an unsigned calculation.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (warning) Expression '-2' has a negative value. That is converted to an unsigned value and used in an unsigned calculation. [signConversion]\n", errout_str()); checkP("void f() {\n" // #12110 FP signConversion with integer overflow " if (LLONG_MIN / (-1)) {}\n" @@ -388,7 +389,7 @@ class TestType : public TestFixture { " return ret;\n" "}\n"; check(code, settings); - ASSERT_EQUALS("[test.cpp:2]: (style) int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (style) int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information. [truncLongCastAssignment]\n", errout_str()); check(code, settingsWin); ASSERT_EQUALS("", errout_str()); @@ -396,7 +397,7 @@ class TestType : public TestFixture { " long ret = x * y;\n" " return ret;\n" "}\n", settings); - ASSERT_EQUALS("[test.cpp:2]: (style) int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (style) int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information. [truncLongCastAssignment]\n", errout_str()); check("long f() {\n" " const long long ret = 256 * (1 << 10);\n" @@ -421,7 +422,7 @@ class TestType : public TestFixture { check("double g(float f) {\n" " return f * f;\n" "}\n", settings); - ASSERT_EQUALS("[test.cpp:2]: (style) float result is returned as double value. If the return value is double to avoid loss of information, then you have loss of information.\n", + ASSERT_EQUALS("[test.cpp:2:5]: (style) float result is returned as double value. If the return value is double to avoid loss of information, then you have loss of information. [truncLongCastReturn]\n", errout_str()); check("void f(int* p) {\n" // #11862 @@ -453,7 +454,7 @@ class TestType : public TestFixture { " return x * y;\n" "}\n"; check(code, settings); - ASSERT_EQUALS("[test.cpp:2]: (style) int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:3]: (style) int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information. [truncLongCastReturn]\n", errout_str()); check(code, settingsWin); ASSERT_EQUALS("", errout_str()); @@ -461,15 +462,15 @@ class TestType : public TestFixture { " return x * y;\n" "}\n"; check(code2, settings); - ASSERT_EQUALS("[test.cpp:2]: (style) int result is returned as long long value. If the return value is long long to avoid loss of information, then you have loss of information.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:3]: (style) int result is returned as long long value. If the return value is long long to avoid loss of information, then you have loss of information. [truncLongCastReturn]\n", errout_str()); check(code2, settingsWin); - ASSERT_EQUALS("[test.cpp:2]: (style) int result is returned as long long value. If the return value is long long to avoid loss of information, then you have loss of information.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:3]: (style) int result is returned as long long value. If the return value is long long to avoid loss of information, then you have loss of information. [truncLongCastReturn]\n", errout_str()); // typedef check("size_t f(int x, int y) {\n" " return x * y;\n" "}\n", settings); - ASSERT_EQUALS("[test.cpp:2]: (style) int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:3]: (style) int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information. [truncLongCastReturn]\n", errout_str()); } // This function ensure that test works with different compilers. Floats can @@ -484,27 +485,27 @@ class TestType : public TestFixture { void checkFloatToIntegerOverflow() { check("x = (int)1E100;", settingsDefault); - ASSERT_EQUALS("[test.cpp:1]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout_str())); + ASSERT_EQUALS("[test.cpp:1:5]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\n", removeFloat(errout_str())); check("void f(void) {\n" " return (int)1E100;\n" "}", settingsDefault); - ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout_str())); + ASSERT_EQUALS("[test.cpp:2:10]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\n", removeFloat(errout_str())); check("void f(void) {\n" " return (int)-1E100;\n" "}", settingsDefault); - ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout_str())); + ASSERT_EQUALS("[test.cpp:2:10]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\n", removeFloat(errout_str())); check("void f(void) {\n" " return (short)1E6;\n" "}", settingsDefault); - ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout_str())); + ASSERT_EQUALS("[test.cpp:2:10]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\n", removeFloat(errout_str())); check("void f(void) {\n" " return (unsigned char)256.0;\n" "}", settingsDefault); - ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout_str())); + ASSERT_EQUALS("[test.cpp:2:10]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\n", removeFloat(errout_str())); check("void f(void) {\n" " return (unsigned char)255.5;\n" @@ -514,12 +515,12 @@ class TestType : public TestFixture { check("void f(void) {\n" " char c = 1234.5;\n" "}", settingsDefault); - ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout_str())); + ASSERT_EQUALS("[test.cpp:2:10]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\n", removeFloat(errout_str())); check("char f(void) {\n" " return 1234.5;\n" "}", settingsDefault); - ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout_str())); + ASSERT_EQUALS("[test.cpp:2:3]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\n", removeFloat(errout_str())); checkP("#define TEST(b, f) b ? 5000 : (unsigned short)f\n" // #11685 "void f()\n" @@ -533,7 +534,7 @@ class TestType : public TestFixture { "{\n" " unsigned short u = TEST(false, 75000.0);\n" "}\n", settingsDefault); - ASSERT_EQUALS("[test.cpp:4]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout_str())); + ASSERT_EQUALS("[test.cpp:4:24]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\n", removeFloat(errout_str())); check( "bool f(unsigned short x);\n" "bool g() {\n" @@ -545,7 +546,7 @@ class TestType : public TestFixture { "bool g() {\n" " return true && f((unsigned short)75000.0);\n" "}\n", settingsDefault); - ASSERT_EQUALS("[test.cpp:3]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout_str())); + ASSERT_EQUALS("[test.cpp:3:22]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\n", removeFloat(errout_str())); check( "bool f(unsigned short x);\n" "bool g() {\n" @@ -557,7 +558,7 @@ class TestType : public TestFixture { "bool g() {\n" " return false || f((unsigned short)75000.0);\n" "}\n", settingsDefault); - ASSERT_EQUALS("[test.cpp:3]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout_str())); + ASSERT_EQUALS("[test.cpp:3:23]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\n", removeFloat(errout_str())); checkP("#define TEST(b, f) b ? 5000 : (unsigned short)f\n" // #11685 "void f()\n" @@ -571,7 +572,7 @@ class TestType : public TestFixture { "{\n" " unsigned short u = TEST(false, 75000.0);\n" "}\n", settingsDefault, dinit(CheckPOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:4]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout_str())); + ASSERT_EQUALS("[test.c:4:24]: (error) Undefined behaviour: float () to integer conversion overflow. [floatConversionOverflow]\n", removeFloat(errout_str())); } @@ -589,14 +590,14 @@ class TestType : public TestFixture { "{\n" " fun(INT_MIN);\n" "}", s); - ASSERT_EQUALS("[test.cpp:3]: (error) Signed integer overflow for expression '-x'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (error) Signed integer overflow for expression '-x'. [integerOverflow]\n", errout_str()); checkP("void f() {\n" // #8399 " int32_t i = INT32_MAX;\n" " i << 1;\n" " i << 2;\n" "}", s); - ASSERT_EQUALS("[test.cpp:4]: (error) Signed integer overflow for expression 'i<<2'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: (error) Signed integer overflow for expression 'i<<2'. [integerOverflow]\n", errout_str()); } void shiftTooManyBits() { // #11496