From 3e7ef23cf11a7fba44c320002686ab543a7d0be8 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 16 May 2025 16:53:22 +0200 Subject: [PATCH] testrunner: aligned multiline template with new default --- test/fixture.cpp | 4 +- test/testbufferoverrun.cpp | 46 ++++++------ test/testclass.cpp | 48 ++++++------ test/testcondition.cpp | 56 +++++++------- test/testnullpointer.cpp | 36 ++++----- test/testother.cpp | 114 ++++++++++++++-------------- test/teststl.cpp | 150 ++++++++++++++++++------------------- 7 files changed, 227 insertions(+), 227 deletions(-) diff --git a/test/fixture.cpp b/test/fixture.cpp index 06890c35f8f..fc285294a41 100644 --- a/test/fixture.cpp +++ b/test/fixture.cpp @@ -466,8 +466,8 @@ void TestFixture::reportErr(const ErrorMessage &msg) void TestFixture::setTemplateFormat(const std::string &templateFormat) { if (templateFormat == "multiline") { - mTemplateFormat = "{file}:{line}:{severity}:{message}"; - mTemplateLocation = "{file}:{line}:note:{info}"; + mTemplateFormat = "[{file}:{line}:{column}]: {severity}:{inconclusive:inconclusive:} {message} [{id}]"; + mTemplateLocation = "[{file}:{line}:{column}]: note: {info}"; } else if (templateFormat == "simple") { // TODO: use the existing one in CmdLineParser mTemplateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]"; diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 5bda0c72ef3..e8a5753557c 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -3505,9 +3505,9 @@ class TestBufferOverrun : public TestFixture { " char *p = malloc(10);\n" " memset(p, 0, 20);\n" "}"); - ASSERT_EQUALS("test.cpp:3:error:Buffer is accessed out of bounds: p\n" - "test.cpp:2:note:Assign p, buffer with size 10\n" - "test.cpp:3:note:Buffer overrun\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: error: Buffer is accessed out of bounds: p [bufferAccessOutOfBounds]\n" + "[test.cpp:2:13]: note: Assign p, buffer with size 10\n" + "[test.cpp:3:12]: note: Buffer overrun\n", errout_str()); settings0 = settingsOld; } @@ -3557,33 +3557,33 @@ class TestBufferOverrun : public TestFixture { " char a[2];\n" " f(a);\n" "}"); - ASSERT_EQUALS("test.cpp:4:warning:Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\n" - "test.cpp:4:note:Function 'f' is called\n" - "test.cpp:1:note:Declaration of 1st function argument.\n" - "test.cpp:3:note:Passing buffer 'a' to function that is declared here\n" - "test.cpp:4:note:Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: warning: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument [argumentSize]\n" + "[test.cpp:4:5]: note: Function 'f' is called\n" + "[test.cpp:1:13]: note: Declaration of 1st function argument.\n" + "[test.cpp:3:10]: note: Passing buffer 'a' to function that is declared here\n" + "[test.cpp:4:5]: note: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\n", errout_str()); check("void f(float a[10][3]);\n" "void g() {\n" " float a[2][3];\n" " f(a);\n" "}"); - ASSERT_EQUALS("test.cpp:4:warning:Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\n" - "test.cpp:4:note:Function 'f' is called\n" - "test.cpp:1:note:Declaration of 1st function argument.\n" - "test.cpp:3:note:Passing buffer 'a' to function that is declared here\n" - "test.cpp:4:note:Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: warning: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument [argumentSize]\n" + "[test.cpp:4:5]: note: Function 'f' is called\n" + "[test.cpp:1:14]: note: Declaration of 1st function argument.\n" + "[test.cpp:3:11]: note: Passing buffer 'a' to function that is declared here\n" + "[test.cpp:4:5]: note: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\n", errout_str()); check("void f(int a[20]);\n" "void g() {\n" " int a[2];\n" " f(a);\n" "}"); - ASSERT_EQUALS("test.cpp:4:warning:Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\n" - "test.cpp:4:note:Function 'f' is called\n" - "test.cpp:1:note:Declaration of 1st function argument.\n" - "test.cpp:3:note:Passing buffer 'a' to function that is declared here\n" - "test.cpp:4:note:Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: warning: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument [argumentSize]\n" + "[test.cpp:4:5]: note: Function 'f' is called\n" + "[test.cpp:1:12]: note: Declaration of 1st function argument.\n" + "[test.cpp:3:9]: note: Passing buffer 'a' to function that is declared here\n" + "[test.cpp:4:5]: note: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument\n", errout_str()); check("void f(int a[]) {\n" " switch (2) {\n" @@ -3613,11 +3613,11 @@ class TestBufferOverrun : public TestFixture { " f(b);\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("test.cpp:8:warning:Buffer 'b' is too small, the function 'f' expects a bigger buffer in 1st argument\n" - "test.cpp:8:note:Function 'f' is called\n" - "test.cpp:1:note:Declaration of 1st function argument.\n" - "test.cpp:7:note:Passing buffer 'b' to function that is declared here\n" - "test.cpp:8:note:Buffer 'b' is too small, the function 'f' expects a bigger buffer in 1st argument\n", + ASSERT_EQUALS("[test.cpp:8:5]: warning: Buffer 'b' is too small, the function 'f' expects a bigger buffer in 1st argument [argumentSize]\n" + "[test.cpp:8:5]: note: Function 'f' is called\n" + "[test.cpp:1:12]: note: Declaration of 1st function argument.\n" + "[test.cpp:7:9]: note: Passing buffer 'b' to function that is declared here\n" + "[test.cpp:8:5]: note: Buffer 'b' is too small, the function 'f' expects a bigger buffer in 1st argument\n", errout_str()); } diff --git a/test/testclass.cpp b/test/testclass.cpp index 3b6a234c4bc..8eeb7eb7696 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -8929,10 +8929,10 @@ class TestClass : public TestFixture { " static C *mInstance;\n" " void hello() {}\n" "};"); - ASSERT_EQUALS("test.cpp:3:warning:Calling method 'hello()' when 'this' might be invalid\n" - "test.cpp:5:note:Assuming 'mInstance' is used as 'this'\n" - "test.cpp:3:note:Delete 'mInstance', invalidating 'this'\n" - "test.cpp:3:note:Call method when 'this' is invalid\n", + ASSERT_EQUALS("[test.cpp:3:38]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\n" + "[test.cpp:5:13]: note: Assuming 'mInstance' is used as 'this'\n" + "[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\n" + "[test.cpp:3:38]: note: Call method when 'this' is invalid\n", errout_str()); checkThisUseAfterFree("class C {\n" @@ -8942,10 +8942,10 @@ class TestClass : public TestFixture { " static std::shared_ptr mInstance;\n" " void hello() {}\n" "};"); - ASSERT_EQUALS("test.cpp:3:warning:Calling method 'hello()' when 'this' might be invalid\n" - "test.cpp:5:note:Assuming 'mInstance' is used as 'this'\n" - "test.cpp:3:note:Delete 'mInstance', invalidating 'this'\n" - "test.cpp:3:note:Call method when 'this' is invalid\n", + ASSERT_EQUALS("[test.cpp:3:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\n" + "[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\n" + "[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\n" + "[test.cpp:3:39]: note: Call method when 'this' is invalid\n", errout_str()); checkThisUseAfterFree("class C {\n" @@ -8956,10 +8956,10 @@ class TestClass : public TestFixture { " void hello();\n" " void reset() { mInstance.reset(); }\n" "};"); - ASSERT_EQUALS("test.cpp:3:warning:Calling method 'hello()' when 'this' might be invalid\n" - "test.cpp:5:note:Assuming 'mInstance' is used as 'this'\n" - "test.cpp:7:note:Delete 'mInstance', invalidating 'this'\n" - "test.cpp:3:note:Call method when 'this' is invalid\n", + ASSERT_EQUALS("[test.cpp:3:29]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\n" + "[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\n" + "[test.cpp:7:18]: note: Delete 'mInstance', invalidating 'this'\n" + "[test.cpp:3:29]: note: Call method when 'this' is invalid\n", errout_str()); // Use member.. @@ -8970,10 +8970,10 @@ class TestClass : public TestFixture { " static C *self;\n" " int x;\n" "};"); - ASSERT_EQUALS("test.cpp:3:warning:Using member 'x' when 'this' might be invalid\n" - "test.cpp:5:note:Assuming 'self' is used as 'this'\n" - "test.cpp:3:note:Delete 'self', invalidating 'this'\n" - "test.cpp:3:note:Call method when 'this' is invalid\n", + ASSERT_EQUALS("[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\n" + "[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\n" + "[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\n" + "[test.cpp:3:33]: note: Call method when 'this' is invalid\n", errout_str()); checkThisUseAfterFree("class C {\n" @@ -8983,10 +8983,10 @@ class TestClass : public TestFixture { " static C *self;\n" " std::map x;\n" "};"); - ASSERT_EQUALS("test.cpp:3:warning:Using member 'x' when 'this' might be invalid\n" - "test.cpp:5:note:Assuming 'self' is used as 'this'\n" - "test.cpp:3:note:Delete 'self', invalidating 'this'\n" - "test.cpp:3:note:Call method when 'this' is invalid\n", + ASSERT_EQUALS("[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\n" + "[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\n" + "[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\n" + "[test.cpp:3:33]: note: Call method when 'this' is invalid\n", errout_str()); // Assign 'shared_from_this()' to non-static smart pointer @@ -8998,10 +8998,10 @@ class TestClass : public TestFixture { " std::shared_ptr mInstance;\n" " void hello() {}\n" "};"); - ASSERT_EQUALS("test.cpp:4:warning:Calling method 'hello()' when 'this' might be invalid\n" - "test.cpp:6:note:Assuming 'mInstance' is used as 'this'\n" - "test.cpp:4:note:Delete 'mInstance', invalidating 'this'\n" - "test.cpp:4:note:Call method when 'this' is invalid\n", + ASSERT_EQUALS("[test.cpp:4:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\n" + "[test.cpp:6:22]: note: Assuming 'mInstance' is used as 'this'\n" + "[test.cpp:4:20]: note: Delete 'mInstance', invalidating 'this'\n" + "[test.cpp:4:39]: note: Call method when 'this' is invalid\n", errout_str()); // Avoid FP.. diff --git a/test/testcondition.cpp b/test/testcondition.cpp index c04b68acbb3..f2c680a5981 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -789,19 +789,19 @@ class TestCondition : public TestFixture { " if (x) {}\n" " else if (!x) {}\n" "}"); - ASSERT_EQUALS("test.cpp:3:style:Expression is always true because 'else if' condition is opposite to previous condition at line 2.\n" - "test.cpp:2:note:first condition\n" - "test.cpp:3:note:else if condition is opposite to first condition\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 2. [multiCondition]\n" + "[test.cpp:2:9]: note: first condition\n" + "[test.cpp:3:14]: note: else if condition is opposite to first condition\n", errout_str()); check("void f(int x) {\n" " int y = x;\n" " if (x) {}\n" " else if (!y) {}\n" "}"); - ASSERT_EQUALS("test.cpp:4:style:Expression is always true because 'else if' condition is opposite to previous condition at line 3.\n" - "test.cpp:2:note:'y' is assigned value 'x' here.\n" - "test.cpp:3:note:first condition\n" - "test.cpp:4:note:else if condition is opposite to first condition\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 3. [multiCondition]\n" + "[test.cpp:2:13]: note: 'y' is assigned value 'x' here.\n" + "[test.cpp:3:9]: note: first condition\n" + "[test.cpp:4:14]: note: else if condition is opposite to first condition\n", errout_str()); } void checkBadBitmaskCheck() { @@ -6021,17 +6021,17 @@ class TestCondition : public TestFixture { " if (x == y)\n" " x = y;\n" "}"); - ASSERT_EQUALS("test.cpp:3:style:Assignment 'x=y' is redundant with condition 'x==y'.\n" - "test.cpp:2:note:Condition 'x==y'\n" - "test.cpp:3:note:Assignment 'x=y' is redundant\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\n" + "[test.cpp:2:11]: note: Condition 'x==y'\n" + "[test.cpp:3:11]: note: Assignment 'x=y' is redundant\n", errout_str()); check("void f(int& x, int y) {\n" " if (x != y)\n" " x = y;\n" "}"); - ASSERT_EQUALS("test.cpp:2:style:The statement 'if (x!=y) x=y' is logically equivalent to 'x=y'.\n" - "test.cpp:3:note:Assignment 'x=y'\n" - "test.cpp:2:note:Condition 'x!=y' is redundant\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: style: The statement 'if (x!=y) x=y' is logically equivalent to 'x=y'. [duplicateConditionalAssign]\n" + "[test.cpp:3:11]: note: Assignment 'x=y'\n" + "[test.cpp:2:11]: note: Condition 'x!=y' is redundant\n", errout_str()); check("void f(int& x, int y) {\n" " if (x == y)\n" @@ -6039,9 +6039,9 @@ class TestCondition : public TestFixture { " else\n" " x = 1;\n" "}"); - ASSERT_EQUALS("test.cpp:3:style:Assignment 'x=y' is redundant with condition 'x==y'.\n" - "test.cpp:2:note:Condition 'x==y'\n" - "test.cpp:3:note:Assignment 'x=y' is redundant\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\n" + "[test.cpp:2:11]: note: Condition 'x==y'\n" + "[test.cpp:3:11]: note: Assignment 'x=y' is redundant\n", errout_str()); check("void f(int& x, int y) {\n" " if (x != y)\n" @@ -6091,18 +6091,18 @@ class TestCondition : public TestFixture { " }\n" " bool b;\n" "};\n"); - ASSERT_EQUALS("test.cpp:4:style:The statement 'if (b) b=true' is redundant.\n" - "test.cpp:4:note:Assignment 'b=true'\n" - "test.cpp:4:note:Condition 'b' is redundant\n" - "test.cpp:5:style:The statement 'if (b) b=false' is logically equivalent to 'b=false'.\n" - "test.cpp:5:note:Assignment 'b=false'\n" - "test.cpp:5:note:Condition 'b' is redundant\n" - "test.cpp:6:style:The statement 'if (!b) b=true' is logically equivalent to 'b=true'.\n" - "test.cpp:6:note:Assignment 'b=true'\n" - "test.cpp:6:note:Condition '!b' is redundant\n" - "test.cpp:7:style:The statement 'if (!b) b=false' is redundant.\n" - "test.cpp:7:note:Assignment 'b=false'\n" - "test.cpp:7:note:Condition '!b' is redundant\n", + ASSERT_EQUALS("[test.cpp:4:13]: style: The statement 'if (b) b=true' is redundant. [duplicateConditionalAssign]\n" + "[test.cpp:4:18]: note: Assignment 'b=true'\n" + "[test.cpp:4:13]: note: Condition 'b' is redundant\n" + "[test.cpp:5:13]: style: The statement 'if (b) b=false' is logically equivalent to 'b=false'. [duplicateConditionalAssign]\n" + "[test.cpp:5:18]: note: Assignment 'b=false'\n" + "[test.cpp:5:13]: note: Condition 'b' is redundant\n" + "[test.cpp:6:13]: style: The statement 'if (!b) b=true' is logically equivalent to 'b=true'. [duplicateConditionalAssign]\n" + "[test.cpp:6:19]: note: Assignment 'b=true'\n" + "[test.cpp:6:13]: note: Condition '!b' is redundant\n" + "[test.cpp:7:13]: style: The statement 'if (!b) b=false' is redundant. [duplicateConditionalAssign]\n" + "[test.cpp:7:19]: note: Assignment 'b=false'\n" + "[test.cpp:7:13]: note: Condition '!b' is redundant\n", errout_str()); } diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 2ff38deb928..454cb06eac5 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -4596,20 +4596,20 @@ class TestNullPointer : public TestFixture { " int *p = 0;\n" " f(p);\n" "}"); - ASSERT_EQUALS("test.cpp:2:error:Null pointer dereference: fp\n" - "test.cpp:5:note:Assignment 'p=0', assigned value is 0\n" - "test.cpp:6:note:Calling function f, 1st argument is null\n" - "test.cpp:2:note:Dereferencing argument fp that is null\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: error: Null pointer dereference: fp [ctunullpointer]\n" + "[test.cpp:5:12]: note: Assignment 'p=0', assigned value is 0\n" + "[test.cpp:6:4]: note: Calling function f, 1st argument is null\n" + "[test.cpp:2:10]: note: Dereferencing argument fp that is null\n", errout_str()); ctu("void use(int *p) { a = *p + 3; }\n" "void call(int x, int *p) { x++; use(p); }\n" "int main() {\n" " call(4,0);\n" "}"); - ASSERT_EQUALS("test.cpp:1:error:Null pointer dereference: p\n" - "test.cpp:4:note:Calling function call, 2nd argument is null\n" - "test.cpp:2:note:Calling function use, 1st argument is null\n" - "test.cpp:1:note:Dereferencing argument p that is null\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:25]: error: Null pointer dereference: p [ctunullpointer]\n" + "[test.cpp:4:7]: note: Calling function call, 2nd argument is null\n" + "[test.cpp:2:33]: note: Calling function use, 1st argument is null\n" + "[test.cpp:1:25]: note: Dereferencing argument p that is null\n", errout_str()); ctu("void dostuff(int *x, int *y) {\n" " if (!var)\n" @@ -4687,11 +4687,11 @@ class TestNullPointer : public TestFixture { " int* q = (int*)malloc(4);\n" " f(q);\n" "}\n"); - ASSERT_EQUALS("test.cpp:2:warning:If memory allocation fails, then there is a possible null pointer dereference: p\n" - "test.cpp:5:note:Assuming allocation function fails\n" - "test.cpp:5:note:Assignment 'q=(int*)malloc(4)', assigned value is 0\n" - "test.cpp:6:note:Calling function f, 1st argument is null\n" - "test.cpp:2:note:Dereferencing argument p that is null\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:6]: warning: If memory allocation fails, then there is a possible null pointer dereference: p [ctunullpointerOutOfMemory]\n" + "[test.cpp:5:26]: note: Assuming allocation function fails\n" + "[test.cpp:5:14]: note: Assignment 'q=(int*)malloc(4)', assigned value is 0\n" + "[test.cpp:6:6]: note: Calling function f, 1st argument is null\n" + "[test.cpp:2:6]: note: Dereferencing argument p that is null\n", errout_str()); // ctu: resource allocation fails ctu("void foo(FILE* f) {\n" @@ -4701,11 +4701,11 @@ class TestNullPointer : public TestFixture { " FILE* f = fopen(notexist,t);\n" " foo(f);\n" "}\n"); - ASSERT_EQUALS("test.cpp:2:warning:If resource allocation fails, then there is a possible null pointer dereference: f\n" - "test.cpp:5:note:Assuming allocation function fails\n" - "test.cpp:5:note:Assignment 'f=fopen(notexist,t)', assigned value is 0\n" - "test.cpp:6:note:Calling function foo, 1st argument is null\n" - "test.cpp:2:note:Dereferencing argument f that is null\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: warning: If resource allocation fails, then there is a possible null pointer dereference: f [ctunullpointerOutOfResources]\n" + "[test.cpp:5:20]: note: Assuming allocation function fails\n" + "[test.cpp:5:20]: note: Assignment 'f=fopen(notexist,t)', assigned value is 0\n" + "[test.cpp:6:8]: note: Calling function foo, 1st argument is null\n" + "[test.cpp:2:13]: note: Dereferencing argument f that is null\n", errout_str()); } }; diff --git a/test/testother.cpp b/test/testother.cpp index 492f111e10e..0eb6218361e 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -9737,9 +9737,9 @@ class TestOther : public TestFixture { " i = 1;\n" " i = 1;\n" "}"); - ASSERT_EQUALS("test.cpp:3:style:Variable 'i' is reassigned a value before the old one has been used.\n" - "test.cpp:2:note:i is assigned\n" - "test.cpp:3:note:i is overwritten\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\n" + "[test.cpp:2:7]: note: i is assigned\n" + "[test.cpp:3:7]: note: i is overwritten\n", errout_str()); // non-local variable => only show warning when inconclusive is used check("int i;\n" @@ -9747,18 +9747,18 @@ class TestOther : public TestFixture { " i = 1;\n" " i = 1;\n" "}"); - ASSERT_EQUALS("test.cpp:4:style:Variable 'i' is reassigned a value before the old one has been used.\n" - "test.cpp:3:note:i is assigned\n" - "test.cpp:4:note:i is overwritten\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\n" + "[test.cpp:3:7]: note: i is assigned\n" + "[test.cpp:4:7]: note: i is overwritten\n", errout_str()); check("void f() {\n" " int i;\n" " i = 1;\n" " i = 1;\n" "}"); - ASSERT_EQUALS("test.cpp:4:style:Variable 'i' is reassigned a value before the old one has been used.\n" - "test.cpp:3:note:i is assigned\n" - "test.cpp:4:note:i is overwritten\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\n" + "[test.cpp:3:7]: note: i is assigned\n" + "[test.cpp:4:7]: note: i is overwritten\n", errout_str()); check("void f() {\n" " static int i;\n" @@ -9772,9 +9772,9 @@ class TestOther : public TestFixture { " i[2] = 1;\n" " i[2] = 1;\n" "}"); - ASSERT_EQUALS("test.cpp:4:style:Variable 'i[2]' is reassigned a value before the old one has been used.\n" - "test.cpp:3:note:i[2] is assigned\n" - "test.cpp:4:note:i[2] is overwritten\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\n" + "[test.cpp:3:10]: note: i[2] is assigned\n" + "[test.cpp:4:10]: note: i[2] is overwritten\n", errout_str()); check("void f(int x) {\n" " int i[10];\n" @@ -9789,9 +9789,9 @@ class TestOther : public TestFixture { " i[x] = 1;\n" " i[x] = 1;\n" "}"); - ASSERT_EQUALS("test.cpp:4:style:Variable 'i[x]' is reassigned a value before the old one has been used.\n" - "test.cpp:3:note:i[x] is assigned\n" - "test.cpp:4:note:i[x] is overwritten\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\n" + "[test.cpp:3:10]: note: i[x] is assigned\n" + "[test.cpp:4:10]: note: i[x] is overwritten\n", errout_str()); // Testing different types check("void f() {\n" @@ -9821,9 +9821,9 @@ class TestOther : public TestFixture { " bar();\n" " i = 1;\n" "}"); - ASSERT_EQUALS("test.cpp:4:style:Variable 'i' is reassigned a value before the old one has been used.\n" - "test.cpp:2:note:i is assigned\n" - "test.cpp:4:note:i is overwritten\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\n" + "[test.cpp:2:7]: note: i is assigned\n" + "[test.cpp:4:7]: note: i is overwritten\n", errout_str()); check("int i;\n" "void f() {\n" @@ -9847,9 +9847,9 @@ class TestOther : public TestFixture { " bar();\n" " i = 1;\n" "}"); - ASSERT_EQUALS("test.cpp:5:style:Variable 'i' is reassigned a value before the old one has been used.\n" - "test.cpp:3:note:i is assigned\n" - "test.cpp:5:note:i is overwritten\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\n" + "[test.cpp:3:7]: note: i is assigned\n" + "[test.cpp:5:7]: note: i is overwritten\n", errout_str()); check("void bar(int i) {}\n" "void f(int i) {\n" @@ -9880,9 +9880,9 @@ class TestOther : public TestFixture { " i = 1;\n" " i = 2;\n" "}"); - ASSERT_EQUALS("test.cpp:5:style:Variable 'i' is reassigned a value before the old one has been used.\n" - "test.cpp:4:note:i is assigned\n" - "test.cpp:5:note:i is overwritten\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\n" + "[test.cpp:4:7]: note: i is assigned\n" + "[test.cpp:5:7]: note: i is overwritten\n", errout_str()); // #4513 check("int x;\n" @@ -9902,9 +9902,9 @@ class TestOther : public TestFixture { " x = 2;\n" " x = g();\n" "}"); - ASSERT_EQUALS("test.cpp:6:style:Variable 'x' is reassigned a value before the old one has been used.\n" - "test.cpp:5:note:x is assigned\n" - "test.cpp:6:note:x is overwritten\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\n" + "[test.cpp:5:7]: note: x is assigned\n" + "[test.cpp:6:7]: note: x is overwritten\n", errout_str()); check("void f() {\n" " Foo& bar = foo();\n" @@ -9952,9 +9952,9 @@ class TestOther : public TestFixture { " x = 1;\n" " return x + 1;\n" "}"); - ASSERT_EQUALS("test.cpp:4:style:Variable 'x' is reassigned a value before the old one has been used.\n" - "test.cpp:3:note:x is assigned\n" - "test.cpp:4:note:x is overwritten\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\n" + "[test.cpp:3:7]: note: x is assigned\n" + "[test.cpp:4:7]: note: x is overwritten\n", errout_str()); // from #3103 (avoid a false positive) check("int foo(){\n" @@ -9978,7 +9978,7 @@ class TestOther : public TestFixture { " x = dostuff();\n" "}"); ASSERT_EQUALS( - "test.cpp:2:style:Variable 'x' can be declared as pointer to const\n", + "[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\n", errout_str()); check("void f() {\n" @@ -9987,7 +9987,7 @@ class TestOther : public TestFixture { " x = dostuff();\n" "}"); ASSERT_EQUALS( - "test.cpp:2:style:Variable 'x' can be declared as pointer to const\n", + "[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\n", errout_str()); check("int foo() {\n" // #4420 @@ -10007,9 +10007,9 @@ class TestOther : public TestFixture { " ab.a = 2;\n" " return ab.a;\n" "}"); - ASSERT_EQUALS("test.cpp:6:style:Variable 'ab.a' is reassigned a value before the old one has been used.\n" - "test.cpp:5:note:ab.a is assigned\n" - "test.cpp:6:note:ab.a is overwritten\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\n" + "[test.cpp:5:10]: note: ab.a is assigned\n" + "[test.cpp:6:10]: note: ab.a is overwritten\n", errout_str()); check("struct AB { int a; int b; };\n" "\n" @@ -10121,8 +10121,8 @@ class TestOther : public TestFixture { " barney(x);\n" " }\n" "}"); - ASSERT_EQUALS("test.cpp:2:style:The scope of the variable 'p' can be reduced.\n" - "test.cpp:2:style:Variable 'p' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\n" + "[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\n", errout_str()); check("void foo() {\n" @@ -10147,9 +10147,9 @@ class TestOther : public TestFixture { " if (memptr)\n" " memptr = 0;\n" "}"); - ASSERT_EQUALS("test.cpp:4:style:Variable 'memptr' is reassigned a value before the old one has been used.\n" - "test.cpp:3:note:memptr is assigned\n" - "test.cpp:4:note:memptr is overwritten\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\n" + "[test.cpp:3:12]: note: memptr is assigned\n" + "[test.cpp:4:12]: note: memptr is overwritten\n", errout_str()); // Pointer function argument (#3857) check("void f(float * var)\n" @@ -10157,18 +10157,18 @@ class TestOther : public TestFixture { " var[0] = 0.2f;\n" " var[0] = 0.2f;\n" // <-- is initialized twice "}"); - ASSERT_EQUALS("test.cpp:4:style:Variable 'var[0]' is reassigned a value before the old one has been used.\n" - "test.cpp:3:note:var[0] is assigned\n" - "test.cpp:4:note:var[0] is overwritten\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\n" + "[test.cpp:3:10]: note: var[0] is assigned\n" + "[test.cpp:4:10]: note: var[0] is overwritten\n", errout_str()); check("void f(float * var)\n" "{\n" " *var = 0.2f;\n" " *var = 0.2f;\n" // <-- is initialized twice "}"); - ASSERT_EQUALS("test.cpp:4:style:Variable '*var' is reassigned a value before the old one has been used.\n" - "test.cpp:3:note:*var is assigned\n" - "test.cpp:4:note:*var is overwritten\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\n" + "[test.cpp:3:8]: note: *var is assigned\n" + "[test.cpp:4:8]: note: *var is overwritten\n", errout_str()); // Volatile variables check("void f() {\n" @@ -10176,15 +10176,15 @@ class TestOther : public TestFixture { " *reg = 12;\n" " *reg = 34;\n" "}"); - ASSERT_EQUALS("test.cpp:2:style:C-style pointer casting\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:25]: style: C-style pointer casting [cstyleCast]\n", errout_str()); check("void f(std::map& m, int key, int value) {\n" // #6379 " m[key] = value;\n" " m[key] = value;\n" "}\n"); - ASSERT_EQUALS("test.cpp:3:style:Variable 'm[key]' is reassigned a value before the old one has been used.\n" - "test.cpp:2:note:m[key] is assigned\n" - "test.cpp:3:note:m[key] is overwritten\n", + ASSERT_EQUALS("[test.cpp:3:12]: style: Variable 'm[key]' is reassigned a value before the old one has been used. [redundantAssignment]\n" + "[test.cpp:2:12]: note: m[key] is assigned\n" + "[test.cpp:3:12]: note: m[key] is overwritten\n", errout_str()); } @@ -10568,18 +10568,18 @@ class TestOther : public TestFixture { " int err = -ENOMEM;\n" " err = dostuff();\n" "}"); - ASSERT_EQUALS("test.cpp:3:style:Redundant initialization for 'err'. The initialized value is overwritten before it is read.\n" - "test.cpp:2:note:err is initialized\n" - "test.cpp:3:note:err is overwritten\n", + ASSERT_EQUALS("[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\n" + "[test.cpp:2:13]: note: err is initialized\n" + "[test.cpp:3:9]: note: err is overwritten\n", errout_str()); check("void f() {\n" " struct S s = {1,2,3};\n" " s = dostuff();\n" "}"); - ASSERT_EQUALS("test.cpp:3:style:Redundant initialization for 's'. The initialized value is overwritten before it is read.\n" - "test.cpp:2:note:s is initialized\n" - "test.cpp:3:note:s is overwritten\n", + ASSERT_EQUALS("[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\n" + "[test.cpp:2:16]: note: s is initialized\n" + "[test.cpp:3:7]: note: s is overwritten\n", errout_str()); check("void f() {\n" @@ -10587,7 +10587,7 @@ class TestOther : public TestFixture { " p = dostuff();\n" "}"); ASSERT_EQUALS( - "test.cpp:2:style:Variable 'p' can be declared as pointer to const\n", + "[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\n", errout_str()); // "trivial" initialization => do not warn diff --git a/test/teststl.cpp b/test/teststl.cpp index cf369b44416..ef4e4c99f5b 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -233,40 +233,40 @@ class TestStl : public TestFixture { " bar(v[2], v[3]) )\n" // v[3] is accessed " {;}\n" "}\n"); - ASSERT_EQUALS("test.cpp:9:warning:Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[2]' causes access out of bounds.\n" - "test.cpp:8:note:condition 'v.size()>=2'\n" - "test.cpp:9:note:Access out of bounds\n" - "test.cpp:9:warning:Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[3]' causes access out of bounds.\n" - "test.cpp:8:note:condition 'v.size()>=2'\n" - "test.cpp:9:note:Access out of bounds\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:18]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[2]' causes access out of bounds. [containerOutOfBounds]\n" + "[test.cpp:8:17]: note: condition 'v.size()>=2'\n" + "[test.cpp:9:18]: note: Access out of bounds\n" + "[test.cpp:9:24]: warning: Either the condition 'v.size()>=2' is redundant or size of 'v' can be 2. Expression 'v[3]' causes access out of bounds. [containerOutOfBounds]\n" + "[test.cpp:8:17]: note: condition 'v.size()>=2'\n" + "[test.cpp:9:24]: note: Access out of bounds\n", errout_str()); checkNormal("void f() {\n" " std::string s;\n" " s[10] = 1;\n" "}"); - ASSERT_EQUALS("test.cpp:3:error:Out of bounds access in expression 's[10]' because 's' is empty.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:4]: error: Out of bounds access in expression 's[10]' because 's' is empty. [containerOutOfBounds]\n", errout_str()); checkNormal("void f() {\n" " std::string s = \"abcd\";\n" " s[10] = 1;\n" "}"); - ASSERT_EQUALS("test.cpp:3:error:Out of bounds access in 's[10]', if 's' size is 4 and '10' is 10\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:4]: error: Out of bounds access in 's[10]', if 's' size is 4 and '10' is 10 [containerOutOfBounds]\n", errout_str()); checkNormal("void f(std::vector v) {\n" " v.front();\n" " if (v.empty()) {}\n" "}"); - ASSERT_EQUALS("test.cpp:2:warning:Either the condition 'v.empty()' is redundant or expression 'v.front()' causes access out of bounds.\n" - "test.cpp:3:note:condition 'v.empty()'\n" - "test.cpp:2:note:Access out of bounds\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: warning: Either the condition 'v.empty()' is redundant or expression 'v.front()' causes access out of bounds. [containerOutOfBounds]\n" + "[test.cpp:3:16]: note: condition 'v.empty()'\n" + "[test.cpp:2:12]: note: Access out of bounds\n", errout_str()); checkNormal("void f(std::vector v) {\n" " if (v.size() == 3) {}\n" " v[16] = 0;\n" "}"); - ASSERT_EQUALS("test.cpp:3:warning:Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[16]' causes access out of bounds.\n" - "test.cpp:2:note:condition 'v.size()==3'\n" - "test.cpp:3:note:Access out of bounds\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[16]' causes access out of bounds. [containerOutOfBounds]\n" + "[test.cpp:2:18]: note: condition 'v.size()==3'\n" + "[test.cpp:3:6]: note: Access out of bounds\n", errout_str()); checkNormal("void f(std::vector v) {\n" " int i = 16;\n" @@ -274,9 +274,9 @@ class TestStl : public TestFixture { " v[i] = 0;\n" " }\n" "}"); - ASSERT_EQUALS("test.cpp:4:warning:Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[i]' causes access out of bounds.\n" - "test.cpp:3:note:condition 'v.size()==3'\n" - "test.cpp:4:note:Access out of bounds\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: warning: Either the condition 'v.size()==3' is redundant or size of 'v' can be 3. Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\n" + "[test.cpp:3:18]: note: condition 'v.size()==3'\n" + "[test.cpp:4:10]: note: Access out of bounds\n", errout_str()); checkNormal("void f(std::vector v, int i) {\n" " if (v.size() == 3 || i == 16) {}\n" @@ -294,9 +294,9 @@ class TestStl : public TestFixture { " s[2] = 0;\n" " }\n" "}"); - ASSERT_EQUALS("test.cpp:3:warning:Either the condition 's.size()==1' is redundant or size of 's' can be 1. Expression 's[2]' causes access out of bounds.\n" - "test.cpp:2:note:condition 's.size()==1'\n" - "test.cpp:3:note:Access out of bounds\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: warning: Either the condition 's.size()==1' is redundant or size of 's' can be 1. Expression 's[2]' causes access out of bounds. [containerOutOfBounds]\n" + "[test.cpp:2:18]: note: condition 's.size()==1'\n" + "[test.cpp:3:10]: note: Access out of bounds\n", errout_str()); // Do not crash checkNormal("void a() {\n" @@ -323,20 +323,20 @@ class TestStl : public TestFixture { " x = s.begin() + 1;\n" "}"); ASSERT_EQUALS( - "test.cpp:3:error:Out of bounds access in expression 's.begin()+1' because 's' is empty.\n" - "test.cpp:3:error:Out of bounds access in expression 's.begin()+1' because 's' is empty.\n", // duplicate + "[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\n" + "[test.cpp:3:17]: error: Out of bounds access in expression 's.begin()+1' because 's' is empty. [containerOutOfBounds]\n", // duplicate errout_str()); checkNormal("void f(int x) {\n" " std::string s;\n" " auto it = s.begin() + x;\n" "}"); - ASSERT_EQUALS("test.cpp:3:error:Out of bounds access in expression 's.begin()+x' because 's' is empty and 'x' may be non-zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:23]: error: Out of bounds access in expression 's.begin()+x' because 's' is empty and 'x' may be non-zero. [containerOutOfBounds]\n", errout_str()); checkNormal("char fstr1(){const std::string s = \"\"; return s[42]; }\n" "wchar_t fwstr1(){const std::wstring s = L\"\"; return s[42]; }"); - ASSERT_EQUALS("test.cpp:1:error:Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42\n" - "test.cpp:2:error:Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:54]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\n" + "[test.cpp:2:60]: error: Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42 [containerOutOfBounds]\n", errout_str()); checkNormal("char fstr1(){const std::string s = \"\"; return s[1]; }\n" "wchar_t fwstr1(){const std::wstring s = L\"\"; return s[1]; }"); @@ -347,7 +347,7 @@ class TestStl : public TestFixture { " std::vector * pv = &v;\n" " return (*pv)[42];\n" "}"); - ASSERT_EQUALS("test.cpp:4:error:Out of bounds access in expression '(*pv)[42]' because '*pv' is empty.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:17]: error: Out of bounds access in expression '(*pv)[42]' because '*pv' is empty. [containerOutOfBounds]\n", errout_str()); checkNormal("void f() {\n" " std::string s;\n" @@ -362,7 +362,7 @@ class TestStl : public TestFixture { " if(b) ++x;\n" " return s[x];\n" "}"); - ASSERT_EQUALS("test.cpp:5:error:Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 6\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:13]: error: Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 6 [containerOutOfBounds]\n", errout_str()); checkNormal("void f() {\n" " static const int N = 4;\n" @@ -386,7 +386,7 @@ class TestStl : public TestFixture { " if(v.at(b?42:0)) {}\n" "}\n"); ASSERT_EQUALS( - "test.cpp:3:error:Out of bounds access in expression 'v.at(b?42:0)' because 'v' is empty.\n", + "[test.cpp:3:12]: error: Out of bounds access in expression 'v.at(b?42:0)' because 'v' is empty. [containerOutOfBounds]\n", errout_str()); checkNormal("void f(std::vector v, bool b){\n" @@ -394,9 +394,9 @@ class TestStl : public TestFixture { " if(v.at(b?42:0)) {}\n" "}\n"); ASSERT_EQUALS( - "test.cpp:3:warning:Either the condition 'v.size()==1' is redundant or size of 'v' can be 1. Expression 'v.at(b?42:0)' causes access out of bounds.\n" - "test.cpp:2:note:condition 'v.size()==1'\n" - "test.cpp:3:note:Access out of bounds\n", + "[test.cpp:3:16]: warning: Either the condition 'v.size()==1' is redundant or size of 'v' can be 1. Expression 'v.at(b?42:0)' causes access out of bounds. [containerOutOfBounds]\n" + "[test.cpp:2:18]: note: condition 'v.size()==1'\n" + "[test.cpp:3:16]: note: Access out of bounds\n", errout_str()); check("struct T {\n" @@ -524,7 +524,7 @@ class TestStl : public TestFixture { " v.resize(entries);\n" " v[0] = 1;\n" "}\n"); - ASSERT_EQUALS("test.cpp:5:error:Out of bounds access in expression 'v[0]' because 'v' is empty.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:6]: error: Out of bounds access in expression 'v[0]' because 'v' is empty. [containerOutOfBounds]\n", errout_str()); checkNormal("void f(size_t entries) {\n" " if (entries < 2) return;\n" @@ -559,7 +559,7 @@ class TestStl : public TestFixture { " std::vector * pv = &v;\n" " return (*pv).at(42);\n" "}\n"); - ASSERT_EQUALS("test.cpp:4:error:Out of bounds access in expression '(*pv).at(42)' because '*pv' is empty.\n", + ASSERT_EQUALS("[test.cpp:4:20]: error: Out of bounds access in expression '(*pv).at(42)' because '*pv' is empty. [containerOutOfBounds]\n", errout_str()); checkNormal("std::string f(const char* DirName) {\n" @@ -581,7 +581,7 @@ class TestStl : public TestFixture { " return true;\n" " return false;\n" "}\n"); - ASSERT_EQUALS("test.cpp:5:style:Consider using std::any_of algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); checkNormal("std::vector range(int n);\n" "bool f(bool b) {\n" @@ -594,7 +594,7 @@ class TestStl : public TestFixture { " return true;\n" " return false;\n" "}\n"); - ASSERT_EQUALS("test.cpp:7:style:Consider using std::any_of algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:3]: style: Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); checkNormal("bool g();\n" "int f(int x) {\n" @@ -607,7 +607,7 @@ class TestStl : public TestFixture { " return i;\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("test.cpp:8:style:Consider using std::find_if algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); checkNormal("bool g();\n" "int f(int x) {\n" @@ -620,7 +620,7 @@ class TestStl : public TestFixture { " return i;\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("test.cpp:8:style:Consider using std::find_if algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:0]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); checkNormal("bool g();\n" "void f(int x) {\n" @@ -637,9 +637,9 @@ class TestStl : public TestFixture { checkNormal("void foo(const std::vector &v) {\n" " if(v.size() >=1 && v[0] == 4 && v[1] == 2){}\n" "}\n"); - ASSERT_EQUALS("test.cpp:2:warning:Either the condition 'v.size()>=1' is redundant or size of 'v' can be 1. Expression 'v[1]' causes access out of bounds.\n" - "test.cpp:2:note:condition 'v.size()>=1'\n" - "test.cpp:2:note:Access out of bounds\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:38]: warning: Either the condition 'v.size()>=1' is redundant or size of 'v' can be 1. Expression 'v[1]' causes access out of bounds. [containerOutOfBounds]\n" + "[test.cpp:2:17]: note: condition 'v.size()>=1'\n" + "[test.cpp:2:38]: note: Access out of bounds\n", errout_str()); checkNormal("int f(int x, int y) {\n" " std::vector a = {0,1,2};\n" @@ -650,9 +650,9 @@ class TestStl : public TestFixture { " return y;\n" "}\n"); ASSERT_EQUALS( - "test.cpp:6:warning:Either the condition 'x<2' is redundant or 'x' can have the value greater or equal to 3. Expression 'a[x]' causes access out of bounds.\n" - "test.cpp:3:note:condition 'x<2'\n" - "test.cpp:6:note:Access out of bounds\n", + "[test.cpp:6:14]: warning: Either the condition 'x<2' is redundant or 'x' can have the value greater or equal to 3. Expression 'a[x]' causes access out of bounds. [containerOutOfBounds]\n" + "[test.cpp:3:9]: note: condition 'x<2'\n" + "[test.cpp:6:14]: note: Access out of bounds\n", errout_str()); checkNormal("int f(std::vector v) {\n" @@ -701,12 +701,12 @@ class TestStl : public TestFixture { " if (v[i]) {}\n" " }\n" "}\n"); - ASSERT_EQUALS("test.cpp:3:warning:Either the condition 'i<=(int)v.size()' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds.\n" - "test.cpp:2:note:condition 'i<=(int)v.size()'\n" - "test.cpp:3:note:Access out of bounds\n" - "test.cpp:6:warning:Either the condition 'i<=static_cast(v.size())' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds.\n" - "test.cpp:5:note:condition 'i<=static_cast(v.size())'\n" - "test.cpp:6:note:Access out of bounds\n", + ASSERT_EQUALS("[test.cpp:3:14]: warning: Either the condition 'i<=(int)v.size()' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\n" + "[test.cpp:2:11]: note: condition 'i<=(int)v.size()'\n" + "[test.cpp:3:14]: note: Access out of bounds\n" + "[test.cpp:6:14]: warning: Either the condition 'i<=static_cast(v.size())' is redundant or 'i' can have the value v.size(). Expression 'v[i]' causes access out of bounds. [containerOutOfBounds]\n" + "[test.cpp:5:11]: note: condition 'i<=static_cast(v.size())'\n" + "[test.cpp:6:14]: note: Access out of bounds\n", errout_str()); check("template\n" @@ -719,7 +719,7 @@ class TestStl : public TestFixture { " b(buf.begin());\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("test.cpp:4:error:Out of bounds access in expression 'd+c.length()' because 'buf' is empty.\n", + ASSERT_EQUALS("[test.cpp:4:5]: error: Out of bounds access in expression 'd+c.length()' because 'buf' is empty. [containerOutOfBounds]\n", errout_str()); check("template\n" @@ -739,9 +739,9 @@ class TestStl : public TestFixture { "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( - "test.cpp:2:warning:Either the condition 'v.empty()' is redundant or expression 'v.back()' causes access out of bounds.\n" - "test.cpp:2:note:condition 'v.empty()'\n" - "test.cpp:2:note:Access out of bounds\n", + "[test.cpp:2:36]: warning: Either the condition 'v.empty()' is redundant or expression 'v.back()' causes access out of bounds. [containerOutOfBounds]\n" + "[test.cpp:2:20]: note: condition 'v.empty()'\n" + "[test.cpp:2:36]: note: Access out of bounds\n", errout_str()); check("std::vector g() {\n" // #10779 @@ -750,7 +750,7 @@ class TestStl : public TestFixture { " v[i] = 42;\n" " return v;\n" "}\n"); - ASSERT_EQUALS("test.cpp:4:error:Out of bounds access in 'v[i]', if 'v' size is 10 and 'i' is 10\n", + ASSERT_EQUALS("[test.cpp:4:10]: error: Out of bounds access in 'v[i]', if 'v' size is 10 and 'i' is 10 [containerOutOfBounds]\n", errout_str()); check("void f() {\n" @@ -758,14 +758,14 @@ class TestStl : public TestFixture { " std::vector v(s);\n" " v[100] = 1;\n" "}\n"); - ASSERT_EQUALS("test.cpp:4:error:Out of bounds access in 'v[100]', if 'v' size is 2 and '100' is 100\n", + ASSERT_EQUALS("[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 2 and '100' is 100 [containerOutOfBounds]\n", errout_str()); check("void f() {\n" " std::vector v({ 1, 2, 3 });\n" " v[100] = 1;\n" "}\n"); - ASSERT_EQUALS("test.cpp:3:error:Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100\n", + ASSERT_EQUALS("[test.cpp:3:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\n", errout_str()); check("void f() {\n" @@ -773,7 +773,7 @@ class TestStl : public TestFixture { " std::vector v(c, sizeof(c) + c);\n" " v[100] = 1;\n" "}\n"); - ASSERT_EQUALS("test.cpp:4:error:Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100\n", + ASSERT_EQUALS("[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\n", errout_str()); check("void f() {\n" @@ -781,7 +781,7 @@ class TestStl : public TestFixture { " std::vector v{ c, c + sizeof(c) };\n" " v[100] = 1;\n" "}\n"); - ASSERT_EQUALS("test.cpp:4:error:Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100\n", + ASSERT_EQUALS("[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\n", errout_str()); check("void f() {\n" @@ -789,7 +789,7 @@ class TestStl : public TestFixture { " std::vector v(i, i + sizeof(i) / 4);\n" " v[100] = 1;\n" "}\n"); - ASSERT_EQUALS("test.cpp:4:error:Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100\n", + ASSERT_EQUALS("[test.cpp:4:6]: error: Out of bounds access in 'v[100]', if 'v' size is 3 and '100' is 100 [containerOutOfBounds]\n", errout_str()); check("void f() {\n" // #6615 @@ -811,10 +811,10 @@ class TestStl : public TestFixture { " static constexpr std::array d = {};\n" " d[10];\n" "}\n"); - ASSERT_EQUALS("test.cpp:3:error:Out of bounds access in 'a[10]', if 'a' size is 10 and '10' is 10\n" - "test.cpp:5:error:Out of bounds access in 'b[10]', if 'b' size is 10 and '10' is 10\n" - "test.cpp:7:error:Out of bounds access in 'c[10]', if 'c' size is 10 and '10' is 10\n" - "test.cpp:9:error:Out of bounds access in 'd[10]', if 'd' size is 10 and '10' is 10\n", + ASSERT_EQUALS("[test.cpp:3:6]: error: Out of bounds access in 'a[10]', if 'a' size is 10 and '10' is 10 [containerOutOfBounds]\n" + "[test.cpp:5:6]: error: Out of bounds access in 'b[10]', if 'b' size is 10 and '10' is 10 [containerOutOfBounds]\n" + "[test.cpp:7:6]: error: Out of bounds access in 'c[10]', if 'c' size is 10 and '10' is 10 [containerOutOfBounds]\n" + "[test.cpp:9:6]: error: Out of bounds access in 'd[10]', if 'd' size is 10 and '10' is 10 [containerOutOfBounds]\n", errout_str()); check("struct test_fixed {\n" @@ -825,7 +825,7 @@ class TestStl : public TestFixture { " test_fixed x = test_fixed();\n" " x.index(10);\n" "}\n"); - ASSERT_EQUALS("test.cpp:3:error:Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10\n", + ASSERT_EQUALS("[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\n", errout_str()); check("struct test_constexpr {\n" @@ -836,7 +836,7 @@ class TestStl : public TestFixture { " test_constexpr x = test_constexpr();\n" " x.index(10);\n" "}\n"); - ASSERT_EQUALS("test.cpp:3:error:Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10\n", + ASSERT_EQUALS("[test.cpp:3:30]: error: Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10 [containerOutOfBounds]\n", errout_str()); checkNormal("struct A {\n" @@ -934,7 +934,7 @@ class TestStl : public TestFixture { " std::string_view sv(s);\n" " return s[2];\n" "}\n"); - ASSERT_EQUALS("test.cpp:4:error:Out of bounds access in expression 's[2]' because 's' is empty.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: error: Out of bounds access in expression 's[2]' because 's' is empty. [containerOutOfBounds]\n", errout_str()); checkNormal("void f() {\n" // #12738 " std::vector v{ 0, 0.1 };\n" @@ -961,27 +961,27 @@ class TestStl : public TestFixture { checkNormal("void f(std::string s) {\n" " s[s.size()] = 1;\n" "}"); - ASSERT_EQUALS("test.cpp:2:error:Out of bounds access of s, index 's.size()' is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\n", errout_str()); checkNormal("void f(std::string s) {\n" " s[s.size()+1] = 1;\n" "}"); - ASSERT_EQUALS("test.cpp:2:error:Out of bounds access of s, index 's.size()+1' is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:3]: error: Out of bounds access of s, index 's.size()+1' is out of bounds. [containerOutOfBoundsIndexExpression]\n", errout_str()); checkNormal("void f(std::string s) {\n" " s[1+s.size()] = 1;\n" "}"); - ASSERT_EQUALS("test.cpp:2:error:Out of bounds access of s, index '1+s.size()' is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:3]: error: Out of bounds access of s, index '1+s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\n", errout_str()); checkNormal("void f(std::string s) {\n" " s[x*s.size()] = 1;\n" "}"); - ASSERT_EQUALS("test.cpp:2:error:Out of bounds access of s, index 'x*s.size()' is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:3]: error: Out of bounds access of s, index 'x*s.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\n", errout_str()); checkNormal("bool f(std::string_view& sv) {\n" // #10031 " return sv[sv.size()] == '\\0';\n" "}\n"); - ASSERT_EQUALS("test.cpp:2:error:Out of bounds access of sv, index 'sv.size()' is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: error: Out of bounds access of sv, index 'sv.size()' is out of bounds. [containerOutOfBoundsIndexExpression]\n", errout_str()); } void outOfBoundsIterator() { check("int f() {\n" @@ -2661,10 +2661,10 @@ class TestStl : public TestFixture { "void g(const std::vector& w) {\n" " f(-1, w);\n" "}\n"); - ASSERT_EQUALS("test.cpp:5:warning:Array index -1 is out of bounds.\n" - "test.cpp:8:note:Calling function 'f', 1st argument '-1' value is -1\n" - "test.cpp:3:note:Assuming condition is false\n" - "test.cpp:5:note:Negative array index\n", + ASSERT_EQUALS("[test.cpp:5:9]: warning: Array index -1 is out of bounds. [negativeContainerIndex]\n" + "[test.cpp:8:8]: note: Calling function 'f', 1st argument '-1' value is -1\n" + "[test.cpp:3:9]: note: Assuming condition is false\n" + "[test.cpp:5:9]: note: Negative array index\n", errout_str()); settings = oldSettings;