diff --git a/test/testclass.cpp b/test/testclass.cpp index 0989bc09535..11b71b14b8c 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -40,6 +40,7 @@ class TestClass : public TestFixture { const Settings settings3 = settingsBuilder().severity(Severity::style).library("std.cfg").severity(Severity::warning).build(); void run() override { + mNewTemplate = true; TEST_CASE(virtualDestructor1); // Base class not found => no error TEST_CASE(virtualDestructor2); // Base class doesn't have a destructor TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual @@ -397,7 +398,7 @@ class TestClass : public TestFixture { checkExplicitConstructors("class Class {\n" " Class(int i) { }\n" "};"); - ASSERT_EQUALS("[test.cpp:2]: (style) Class 'Class' has a constructor with 1 argument that is not explicit.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (style) Class 'Class' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\n", errout_str()); checkExplicitConstructors("class Class {\n" " Class(const Class& other) { }\n" @@ -433,7 +434,7 @@ class TestClass : public TestFixture { " Test test;\n" " return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Struct 'Test < int >' has a constructor with 1 argument that is not explicit.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:3]: (style) Struct 'Test < int >' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\n", errout_str()); // #7465: No error for copy or move constructors checkExplicitConstructors("template struct Test {\n" @@ -459,7 +460,7 @@ class TestClass : public TestFixture { checkExplicitConstructors("struct A{" " A(int, int y=2) {}" "};"); - ASSERT_EQUALS("[test.cpp:1]: (style) Struct 'A' has a constructor with 1 argument that is not explicit.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:14]: (style) Struct 'A' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\n", errout_str()); checkExplicitConstructors("struct Foo {\n" // #10515 " template \n" @@ -479,7 +480,7 @@ class TestClass : public TestFixture { " Branch(Token* tok = nullptr) : endBlock(tok) {}\n" " Token* endBlock = nullptr;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Struct 'Branch' has a constructor with 1 argument that is not explicit.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (style) Struct 'Branch' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\n", errout_str()); checkExplicitConstructors("struct S {\n" " S(std::initializer_list il) : v(il) {}\n" @@ -499,8 +500,8 @@ class TestClass : public TestFixture { " Color(unsigned int rgba);\n" " Color(std::uint8_t r = 0, std::uint8_t g = 0, std::uint8_t b = 0, std::uint8_t a = 255);\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Class 'Color' has a constructor with 1 argument that is not explicit.\n" - "[test.cpp:4]: (style) Class 'Color' has a constructor with 1 argument that is not explicit.\n", + ASSERT_EQUALS("[test.cpp:3:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\n" + "[test.cpp:4:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\n", errout_str()); } @@ -532,7 +533,7 @@ class TestClass : public TestFixture { "struct Derived : Base {\n" " int x;\n" "};"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\n", errout_str()); checkDuplInheritedMembers("class Base {\n" " protected:\n" @@ -541,7 +542,7 @@ class TestClass : public TestFixture { "struct Derived : public Base {\n" " int x;\n" "};"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\n", errout_str()); checkDuplInheritedMembers("class Base0 {\n" " int x;\n" @@ -564,7 +565,7 @@ class TestClass : public TestFixture { "struct Derived : Base0, Base1 {\n" " int x;\n" "};"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:9]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:9:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\n", errout_str()); checkDuplInheritedMembers("class Base0 {\n" " protected:\n" @@ -577,8 +578,8 @@ class TestClass : public TestFixture { "struct Derived : Base0, Base1 {\n" " int x;\n" "};"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:10]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'.\n" - "[test.cpp:7] -> [test.cpp:10]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\n" + "[test.cpp:7:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'. [duplInheritedMember]\n", errout_str()); checkDuplInheritedMembers("class Base {\n" " int x;\n" @@ -633,7 +634,7 @@ class TestClass : public TestFixture { "class Derived2 : public Derived1 {\n" " int i;\n" "};"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:10]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13] -> [test.cpp:10:9]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'. [duplInheritedMember]\n", errout_str()); // don't crash on recursive template checkDuplInheritedMembers("template\n" @@ -669,7 +670,7 @@ class TestClass : public TestFixture { " int g() const;\n" " int f() const override { return g(); }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:6]: (warning) The struct 'D' defines member function with name 'g' also defined in its parent struct 'B'.\n", + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:6:9]: (warning) The struct 'D' defines member function with name 'g' also defined in its parent struct 'B'. [duplInheritedMember]\n", errout_str()); checkDuplInheritedMembers("struct B {\n" @@ -764,9 +765,9 @@ class TestClass : public TestFixture { " ~F();\n" " F& operator=(const F&f);\n" "};"); - TODO_ASSERT_EQUALS("[test.cpp:4]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\n" + TODO_ASSERT_EQUALS("[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\n" "[test.cpp:3] -> [test.cpp:7]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\n", - "[test.cpp:4]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\n" + "[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\n" , errout_str()); checkCopyConstructor("class F\n" @@ -940,7 +941,7 @@ class TestClass : public TestFixture { " ~F();\n" " F& operator=(const F&f);\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:7]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s). [noCopyConstructor]\n", errout_str()); checkCopyConstructor("class F {\n" " char *p;\n" @@ -959,7 +960,7 @@ class TestClass : public TestFixture { " ~F();\n" " F& operator=(const F&f);\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s). [noCopyConstructor]\n", errout_str()); // #7198 checkCopyConstructor("struct F {\n" @@ -1005,7 +1006,7 @@ class TestClass : public TestFixture { " F&operator=(const F &f);\n" " ~F();\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The copy constructor is explicitly defaulted but the default copy constructor does not work well. It is recommended to define or delete the copy constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The copy constructor is explicitly defaulted but the default copy constructor does not work well. It is recommended to define or delete the copy constructor. [noCopyConstructor]\n", errout_str()); } void copyConstructor4() { @@ -1077,7 +1078,7 @@ class TestClass : public TestFixture { " F(const F &f);\n" " ~F();\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Struct 'F' does not have a operator= which is recommended since it has dynamic memory/resource allocation(s).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (warning) Struct 'F' does not have a operator= which is recommended since it has dynamic memory/resource allocation(s). [noOperatorEq]\n", errout_str()); // defaulted operator= checkCopyConstructor("struct F {\n" @@ -1087,7 +1088,7 @@ class TestClass : public TestFixture { " F &operator=(const F &f) = default;\n" " ~F();\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The operator= is explicitly defaulted but the default operator= does not work well. It is recommended to define or delete the operator=.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The operator= is explicitly defaulted but the default operator= does not work well. It is recommended to define or delete the operator=. [noOperatorEq]\n", errout_str()); // deleted operator= checkCopyConstructor("struct F {\n" @@ -1116,7 +1117,7 @@ class TestClass : public TestFixture { " F(const F &f);\n" " F&operator=(const F&);" "};"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource allocation(s).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource allocation(s). [noDestructor]\n", errout_str()); checkCopyConstructor("struct F {\n" " C* c;\n" @@ -1132,7 +1133,7 @@ class TestClass : public TestFixture { " F(const F &f);\n" " F& operator=(const F&);" "};"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource allocation(s).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource allocation(s). [noDestructor]\n", errout_str()); checkCopyConstructor("struct Data { int x; int y; };\n" "struct F {\n" @@ -1141,7 +1142,7 @@ class TestClass : public TestFixture { " F(const F &f);\n" " F&operator=(const F&);" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource allocation(s).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource allocation(s). [noDestructor]\n", errout_str()); // defaulted destructor checkCopyConstructor("struct F {\n" @@ -1151,7 +1152,7 @@ class TestClass : public TestFixture { " F &operator=(const F &f);\n" " ~F() = default;\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The destructor is explicitly defaulted but the default destructor does not work well. It is recommended to define the destructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The destructor is explicitly defaulted but the default destructor does not work well. It is recommended to define the destructor. [noDestructor]\n", errout_str()); // deleted destructor checkCopyConstructor("struct F {\n" @@ -1192,7 +1193,7 @@ class TestClass : public TestFixture { "public:\n" " A & operator=(const A &a) { return a; }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( "class A\n" @@ -1219,7 +1220,7 @@ class TestClass : public TestFixture { " A & operator=(const A &);\n" "};\n" "A & A::operator=(const A &a) { return a; }"); - ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( "class A\n" @@ -1228,7 +1229,7 @@ class TestClass : public TestFixture { " A & operator=(const A &a);\n" "};\n" "A & A::operator=(const A &a) { return a; }"); - ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( "class A\n" @@ -1252,7 +1253,7 @@ class TestClass : public TestFixture { " B & operator=(const B &b) { return b; }\n" " };\n" "};"); - ASSERT_EQUALS("[test.cpp:7]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:13]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( "class A\n" @@ -1278,7 +1279,7 @@ class TestClass : public TestFixture { " };\n" "};\n" "A::B & A::B::operator=(const A::B &b) { return b; }"); - ASSERT_EQUALS("[test.cpp:10]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( "class A {\n" @@ -1288,7 +1289,7 @@ class TestClass : public TestFixture { "{\n" " B & operator=(const B & b) { return b; }\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( "class A {\n" @@ -1299,7 +1300,7 @@ class TestClass : public TestFixture { " B & operator=(const B &);\n" "};\n" "A::B & A::B::operator=(const A::B & b) { return b; }"); - ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( "class A {\n" @@ -1309,7 +1310,7 @@ class TestClass : public TestFixture { "{\n" " A::B & operator=(const A::B & b) { return b; }\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( "class A {\n" @@ -1320,7 +1321,7 @@ class TestClass : public TestFixture { " A::B & operator=(const A::B &);\n" "};\n" "A::B & A::B::operator=(const A::B & b) { return b; }"); - ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( "namespace A {\n" @@ -1330,7 +1331,7 @@ class TestClass : public TestFixture { "{\n" " B & operator=(const B & b) { return b; }\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( "namespace A {\n" @@ -1341,7 +1342,7 @@ class TestClass : public TestFixture { " B & operator=(const B &);\n" "};\n" "A::B & A::B::operator=(const A::B & b) { return b; }"); - ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( "namespace A {\n" @@ -1351,7 +1352,7 @@ class TestClass : public TestFixture { "{\n" " A::B & operator=(const A::B & b) { return b; }\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( "namespace A {\n" @@ -1362,7 +1363,7 @@ class TestClass : public TestFixture { " A::B & operator=(const A::B &);\n" "};\n" "A::B & A::B::operator=(const A::B & b) { return b; }"); - ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( // #11380 "struct S {\n" @@ -1382,7 +1383,7 @@ class TestClass : public TestFixture { "{\n" " szp &operator =(int *other) {}\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); checkOpertorEqRetRefThis( "class szp\n" @@ -1390,7 +1391,7 @@ class TestClass : public TestFixture { " szp &operator =(int *other);\n" "};\n" "szp &szp::operator =(int *other) {}"); - ASSERT_EQUALS("[test.cpp:5]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); checkOpertorEqRetRefThis( "namespace NS {\n" @@ -1400,7 +1401,7 @@ class TestClass : public TestFixture { "{\n" " szp &operator =(int *other) {}\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); checkOpertorEqRetRefThis( "namespace NS {\n" @@ -1411,7 +1412,7 @@ class TestClass : public TestFixture { " szp &operator =(int *other);\n" "};\n" "NS::szp &NS::szp::operator =(int *other) {}"); - ASSERT_EQUALS("[test.cpp:8]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); checkOpertorEqRetRefThis( "namespace NS {\n" @@ -1421,7 +1422,7 @@ class TestClass : public TestFixture { "{\n" " NS::szp &operator =(int *other) {}\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:12]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); checkOpertorEqRetRefThis( "namespace NS {\n" @@ -1432,7 +1433,7 @@ class TestClass : public TestFixture { " NS::szp &operator =(int *other);\n" "};\n" "NS::szp &NS::szp::operator =(int *other) {}"); - ASSERT_EQUALS("[test.cpp:8]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); checkOpertorEqRetRefThis( "class A {\n" @@ -1442,7 +1443,7 @@ class TestClass : public TestFixture { "{\n" " szp &operator =(int *other) {}\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); checkOpertorEqRetRefThis( "class A {\n" @@ -1453,7 +1454,7 @@ class TestClass : public TestFixture { " szp &operator =(int *other);\n" "};\n" "A::szp &A::szp::operator =(int *other) {}"); - ASSERT_EQUALS("[test.cpp:8]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); checkOpertorEqRetRefThis( "class A {\n" @@ -1463,7 +1464,7 @@ class TestClass : public TestFixture { "{\n" " A::szp &operator =(int *other) {}\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); checkOpertorEqRetRefThis( "class A {\n" @@ -1474,7 +1475,7 @@ class TestClass : public TestFixture { " A::szp &operator =(int *other);\n" "};\n" "A::szp &A::szp::operator =(int *other) {}"); - ASSERT_EQUALS("[test.cpp:8]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); } void operatorEqRetRefThis3() { @@ -1555,21 +1556,21 @@ class TestClass : public TestFixture { "public:\n" " A & operator=(const A &a) { }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); checkOpertorEqRetRefThis( "class A {\n" "protected:\n" " A & operator=(const A &a) {}\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( "class A {\n" "private:\n" " A & operator=(const A &a) {}\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style) 'operator=' should return reference to 'this' instance.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( "class A {\n" @@ -1579,7 +1580,7 @@ class TestClass : public TestFixture { " throw std::exception();\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\n", errout_str()); checkOpertorEqRetRefThis( "class A {\n" @@ -1589,7 +1590,7 @@ class TestClass : public TestFixture { " abort();\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\n", errout_str()); checkOpertorEqRetRefThis( "class A {\n" @@ -1597,7 +1598,7 @@ class TestClass : public TestFixture { " A & operator=(const A &a);\n" "};\n" "A & A :: operator=(const A &a) { }"); - ASSERT_EQUALS("[test.cpp:5]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); } void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault) @@ -1698,7 +1699,7 @@ class TestClass : public TestFixture { " return *this;\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); // this test has an assignment test but doesn't need it checkOpertorEqToSelf( @@ -1756,7 +1757,7 @@ class TestClass : public TestFixture { " }\n" " return *this;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); // this test needs an assignment test and has the inverse test checkOpertorEqToSelf( @@ -1775,7 +1776,7 @@ class TestClass : public TestFixture { " }\n" " return *this;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); // this test needs an assignment test and has the inverse test checkOpertorEqToSelf( @@ -1794,7 +1795,7 @@ class TestClass : public TestFixture { " }\n" " return *this;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); // this test needs an assignment test and has the inverse test checkOpertorEqToSelf( @@ -1813,7 +1814,7 @@ class TestClass : public TestFixture { " }\n" " return *this;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); // this test needs an assignment test and has the inverse test checkOpertorEqToSelf( @@ -1832,7 +1833,7 @@ class TestClass : public TestFixture { " }\n" " return *this;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); // this test needs an assignment test and has the inverse test checkOpertorEqToSelf( @@ -1854,7 +1855,7 @@ class TestClass : public TestFixture { " }\n" " return *this;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); // this test needs an assignment test and has the inverse test checkOpertorEqToSelf( @@ -1875,7 +1876,7 @@ class TestClass : public TestFixture { " }\n" " return *this;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); // this test needs an assignment test but doesn’t have it @@ -1892,7 +1893,7 @@ class TestClass : public TestFixture { " s = strdup(a.s);\n" " return *this;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); // ticket #1224 checkOpertorEqToSelf( @@ -1978,7 +1979,7 @@ class TestClass : public TestFixture { " }\n" " };\n" "};"); - ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:13]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); // this test has an assignment test but doesn't need it checkOpertorEqToSelf( @@ -2049,7 +2050,7 @@ class TestClass : public TestFixture { " s = strdup(b.s);\n" " return *this;\n" " }"); - ASSERT_EQUALS("[test.cpp:11]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:11:14]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); } void operatorEqToSelf3() { @@ -2483,7 +2484,7 @@ class TestClass : public TestFixture { "private:\n" " char * data;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); checkOpertorEqToSelf( "class A\n" @@ -2500,7 +2501,7 @@ class TestClass : public TestFixture { " strcpy(data, a.data);\n" " return *this;\n" "};"); - ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); checkOpertorEqToSelf( "class A\n" @@ -2516,7 +2517,7 @@ class TestClass : public TestFixture { "private:\n" " char * data;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); checkOpertorEqToSelf( "class A\n" @@ -2533,7 +2534,7 @@ class TestClass : public TestFixture { " *data = *a.data;\n" " return *this;\n" "};"); - ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); } void operatorEqToSelf7() { @@ -2633,13 +2634,13 @@ class TestClass : public TestFixture { "class Derived : public Base { public: ~Derived() { (void)11; } };" "Base *base = new Derived;\n" "delete base;"); - ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); checkVirtualDestructor("class Base { };\n" "class Derived : protected Base { public: ~Derived() { (void)11; } };" "Base *base = new Derived;\n" "delete base;"); - ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); checkVirtualDestructor("class Base { };\n" "class Derived : private Base { public: ~Derived() { (void)11; } };" @@ -2672,7 +2673,7 @@ class TestClass : public TestFixture { " Base* p = new Derived();\n" " delete p;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); checkVirtualDestructor("using namespace std;\n" "struct A\n" @@ -2693,7 +2694,7 @@ class TestClass : public TestFixture { " Base* p = new Derived();\n" " delete p;\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); } void virtualDestructor3() { @@ -2703,19 +2704,19 @@ class TestClass : public TestFixture { "class Derived : public Base { public: ~Derived() { (void)11; } };" "Base *base = new Derived;\n" "delete base;"); - ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); checkVirtualDestructor("class Base { public: ~Base(); };\n" "class Derived : protected Base { public: ~Derived() { (void)11; } };" "Base *base = new Derived;\n" "delete base;"); - ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); checkVirtualDestructor("class Base { public: ~Base(); };\n" "class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };" "Base *base = new Derived;\n" "delete base;"); - ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); } void virtualDestructor4() { @@ -2725,13 +2726,13 @@ class TestClass : public TestFixture { "class Derived : public Base { };" "Base *base = new Derived;\n" "delete base;"); - ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); checkVirtualDestructor("class Base { public: ~Base(); };\n" "class Derived : private Fred, public Base { };" "Base *base = new Derived;\n" "delete base;"); - ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); } void virtualDestructor5() { @@ -2741,13 +2742,13 @@ class TestClass : public TestFixture { "class Derived : public Base { public: ~Derived() {} };" "Base *base = new Derived;\n" "delete base;"); - ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); checkVirtualDestructor("class Base { public: ~Base(); };\n" "class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}" "Base *base = new Derived;\n" "delete base;"); - ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); } void virtualDestructor6() { @@ -2888,7 +2889,7 @@ class TestClass : public TestFixture { "};\n" "\n" "AA *p = new B; delete p;"); - ASSERT_EQUALS("[test.cpp:9]: (error) Class 'AA < double >' which is inherited by class 'B' does not have a virtual destructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:3]: (error) Class 'AA < double >' which is inherited by class 'B' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); } void virtualDestructorInconclusive() { @@ -2897,7 +2898,7 @@ class TestClass : public TestFixture { " ~Base(){}\n" " virtual void foo(){}\n" "};\n", dinit(CheckVirtualDestructorOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Class 'Base' which has virtual members does not have a virtual destructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: (warning, inconclusive) Class 'Base' which has virtual members does not have a virtual destructor. [virtualDestructor]\n", errout_str()); checkVirtualDestructor("class Base {\n" "public:\n" @@ -2912,7 +2913,7 @@ class TestClass : public TestFixture { " Base * base = new Derived();\n" " delete base;\n" "}\n", dinit(CheckVirtualDestructorOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); // class Base destructor is not virtual but protected -> no error checkVirtualDestructor("class Base {\n" @@ -2992,7 +2993,7 @@ class TestClass : public TestFixture { " Fred fred;\n" " memset(&fred, 0, sizeof(Fred));\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\n", errout_str()); checkNoMemset("class Fred\n" "{\n" @@ -3003,7 +3004,7 @@ class TestClass : public TestFixture { " Fred fred;\n" " memset(&fred, 0, sizeof(Fred));\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\n", errout_str()); checkNoMemset("class Fred {\n" " std::string b;\n" @@ -3012,7 +3013,7 @@ class TestClass : public TestFixture { "void Fred::f() {\n" " memset(this, 0, sizeof(*this));\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\n", errout_str()); checkNoMemset("class Fred\n" "{\n" @@ -3033,7 +3034,7 @@ class TestClass : public TestFixture { " Fred fred;\n" " memset(&fred, 0, sizeof(fred));\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\n", errout_str()); checkNoMemset("class Fred\n" "{\n" @@ -3045,7 +3046,7 @@ class TestClass : public TestFixture { " Pebbles pebbles;\n" " memset(&pebbles, 0, sizeof(pebbles));\n" "}"); - ASSERT_EQUALS("[test.cpp:9]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\n", errout_str()); checkNoMemset("class Fred\n" "{\n" @@ -3056,7 +3057,7 @@ class TestClass : public TestFixture { " Fred fred;\n" " memset(&fred, 0, sizeof(fred));\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a virtual function.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\n", errout_str()); checkNoMemset("class Fred\n" "{\n" @@ -3067,7 +3068,7 @@ class TestClass : public TestFixture { " static Fred fred;\n" " memset(&fred, 0, sizeof(fred));\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on class that contains a virtual function.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\n", errout_str()); checkNoMemset("class Fred\n" "{\n" @@ -3082,7 +3083,7 @@ class TestClass : public TestFixture { " Pebbles pebbles;\n" " memset(&pebbles, 0, sizeof(pebbles));\n" "}"); - ASSERT_EQUALS("[test.cpp:12]: (error) Using 'memset' on class that contains a virtual function.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:12:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\n", errout_str()); // Fred not defined in scope checkNoMemset("namespace n1 {\n" @@ -3110,7 +3111,7 @@ class TestClass : public TestFixture { " n1::Fred fred;\n" " memset(&fred, 0, sizeof(n1::Fred));\n" "}"); - ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\n", errout_str()); // Fred with namespace qualifier checkNoMemset("namespace n1 {\n" @@ -3124,7 +3125,7 @@ class TestClass : public TestFixture { " n1::Fred fred;\n" " memset(&fred, 0, sizeof(fred));\n" "}"); - ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\n", errout_str()); checkNoMemset("class A {\n" " virtual ~A() { }\n" @@ -3154,7 +3155,7 @@ class TestClass : public TestFixture { " A a;\n" " memset(&a, 0, sizeof(a));\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Using 'memset' on class that contains a reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\n", errout_str()); checkNoMemset("class A {\n" " const B&b;\n" "};\n" @@ -3162,7 +3163,7 @@ class TestClass : public TestFixture { " A a;\n" " memset(&a, 0, sizeof(a));\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Using 'memset' on class that contains a reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\n", errout_str()); // #7456 checkNoMemset("struct A {\n" @@ -3187,10 +3188,10 @@ class TestClass : public TestFixture { " memset(&v[0], 0, 5 * sizeof(S));\n" " memset(&v[0], 0, sizeof(S) * 5);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Using 'memset' on struct that contains a 'std::vector'.\n" - "[test.cpp:5]: (error) Using 'memset' on struct that contains a 'std::vector'.\n" - "[test.cpp:6]: (error) Using 'memset' on struct that contains a 'std::vector'.\n" - "[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'.\n", + ASSERT_EQUALS("[test.cpp:4:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\n" + "[test.cpp:5:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\n" + "[test.cpp:6:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\n" + "[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\n", errout_str()); // #1655 @@ -3200,7 +3201,7 @@ class TestClass : public TestFixture { " std::string s;\n" " memcpy(&s, c, strlen(c) + 1);\n" "}\n", s); - ASSERT_EQUALS("[test.cpp:4]: (error) Using 'memcpy' on std::string.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (error) Using 'memcpy' on std::string. [memsetClass]\n", errout_str()); checkNoMemset("template \n" " void f(T* dst, const T* src, int N) {\n" @@ -3286,7 +3287,7 @@ class TestClass : public TestFixture { " struct A fail;\n" " memset(&fail, 0, sizeof(struct A));\n" "}"); - ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:2]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\n", errout_str()); checkNoMemset("struct Fred\n" "{\n" @@ -3297,7 +3298,7 @@ class TestClass : public TestFixture { " Fred fred;\n" " memset(&fred, 0, sizeof(fred));\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\n", errout_str()); checkNoMemset("struct Stringy {\n" " std::string inner;\n" @@ -3310,7 +3311,7 @@ class TestClass : public TestFixture { " memset(&foo, 0, sizeof(Foo));\n" "}"); - ASSERT_EQUALS("[test.cpp:9]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\n", errout_str()); } void memsetVector() { @@ -3322,7 +3323,7 @@ class TestClass : public TestFixture { " A a;\n" " memset(&a, 0, sizeof(A));\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on class that contains a 'std::vector'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\n", errout_str()); checkNoMemset("struct A\n" "{ std::vector ints; };\n" @@ -3332,7 +3333,7 @@ class TestClass : public TestFixture { " A a;\n" " memset(&a, 0, sizeof(A));\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\n", errout_str()); checkNoMemset("struct A\n" "{ std::vector ints; };\n" @@ -3342,7 +3343,7 @@ class TestClass : public TestFixture { " A a;\n" " memset(&a, 0, sizeof(struct A));\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\n", errout_str()); checkNoMemset("struct A\n" "{ std::vector ints; };\n" @@ -3352,7 +3353,7 @@ class TestClass : public TestFixture { " A a;\n" " memset(&a, 0, sizeof(a));\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\n", errout_str()); checkNoMemset("class A\n" "{ std::vector< std::vector > ints; };\n" @@ -3362,7 +3363,7 @@ class TestClass : public TestFixture { " A a;\n" " memset(&a, 0, sizeof(A));\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on class that contains a 'std::vector'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\n", errout_str()); checkNoMemset("struct A\n" "{ std::vector< std::vector > ints; };\n" @@ -3372,7 +3373,7 @@ class TestClass : public TestFixture { " A a;\n" " memset(&a, 0, sizeof(A));\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\n", errout_str()); checkNoMemset("struct A\n" "{ std::vector< std::vector > ints; };\n" @@ -3382,7 +3383,7 @@ class TestClass : public TestFixture { " A a;\n" " memset(&a, 0, sizeof(a));\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\n", errout_str()); checkNoMemset("struct A\n" "{ std::vector ints; };\n" @@ -3392,7 +3393,7 @@ class TestClass : public TestFixture { " A a;\n" " memset(&a, 0, sizeof(A));\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\n", errout_str()); checkNoMemset("struct A {\n" " std::vector buf;\n" @@ -3420,10 +3421,10 @@ class TestClass : public TestFixture { " memset(c2, 0, 10);\n" " memset(c3, 0, 10);\n" "}"); - ASSERT_EQUALS("[test.cpp:9]: (error) Using 'memset' on struct that contains a 'std::string'.\n" - "[test.cpp:11]: (error) Using 'memset' on struct that contains a 'std::string'.\n" - "[test.cpp:12]: (error) Using 'memset' on struct that contains a 'std::string'.\n" - "[test.cpp:13]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\n" + "[test.cpp:11:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\n" + "[test.cpp:12:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\n" + "[test.cpp:13:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\n", errout_str()); // Ticket #6953 checkNoMemset("typedef float realnum;\n" @@ -3436,7 +3437,7 @@ class TestClass : public TestFixture { " memset(d, 0, sizeof(multilevel_data));\n" " return (void*) d;\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (portability) Using memset() on struct which contains a floating point number.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:3]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\n", errout_str()); } void memsetOnStdPodType() { // Ticket #5901 @@ -3476,7 +3477,7 @@ class TestClass : public TestFixture { " A a;\n" " memset(&a, 0, sizeof(A));\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (portability) Using memset() on struct which contains a floating point number.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\n", errout_str()); checkNoMemset("struct A {\n" " float f[4];\n" @@ -3485,7 +3486,7 @@ class TestClass : public TestFixture { " A a;\n" " memset(&a, 0, sizeof(A));\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (portability) Using memset() on struct which contains a floating point number.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\n", errout_str()); checkNoMemset("struct A {\n" " float f[4];\n" @@ -3519,31 +3520,31 @@ class TestClass : public TestFixture { "void foo(C*& p) {\n" " p = malloc(sizeof(C));\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\n", errout_str()); checkNoMemset("class C { C(int z, Foo bar) { bar(); } };\n" "void foo(C*& p) {\n" " p = malloc(sizeof(C));\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\n", errout_str()); checkNoMemset("struct C { C() {} };\n" "void foo(C*& p) {\n" " p = realloc(p, sizeof(C));\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:1]: (warning) Memory for class instance allocated with realloc(), but class provides constructors.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with realloc(), but class provides constructors. [mallocOnClassWarning]\n", errout_str()); checkNoMemset("struct C { virtual void bar(); };\n" "void foo(C*& p) {\n" " p = malloc(sizeof(C));\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:1]: (error) Memory for class instance allocated with malloc(), but class contains a virtual function.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a virtual function. [mallocOnClassError]\n", errout_str()); checkNoMemset("struct C { std::string s; };\n" "void foo(C*& p) {\n" " p = malloc(sizeof(C));\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:1]: (error) Memory for class instance allocated with malloc(), but class contains a 'std::string'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a 'std::string'. [mallocOnClassError]\n", errout_str()); checkNoMemset("class C { };\n" // C-Style class/struct "void foo(C*& p) {\n" @@ -3598,20 +3599,20 @@ class TestClass : public TestFixture { void this_subtraction() { checkThisSubtraction("; this-x ;"); - ASSERT_EQUALS("[test.cpp:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\n", errout_str()); checkThisSubtraction("; *this = *this-x ;"); ASSERT_EQUALS("", errout_str()); checkThisSubtraction("; *this = *this-x ;\n" "this-x ;"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\n", errout_str()); checkThisSubtraction("; *this = *this-x ;\n" "this-x ;\n" "this-x ;"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?\n" - "[test.cpp:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\n" + "[test.cpp:3:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\n", errout_str()); } struct CheckConstOptions @@ -3639,18 +3640,18 @@ class TestClass : public TestFixture { " int a;\n" " int getA() { return a; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'Fred::getA' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\n", errout_str()); checkConst("class Fred {\n" " const std::string foo() { return \"\"; }\n" "};"); - ASSERT_EQUALS("[test.cpp:2]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("class Fred {\n" " std::string s;\n" " const std::string & foo() { return \"\"; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:25]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); // constructors can't be const.. checkConst("class Fred {\n" @@ -3682,14 +3683,14 @@ class TestClass : public TestFixture { " int a() const { return x; }\n" " void b() { a(); }\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (style, inconclusive) Technically the member function 'Fred::b' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (style, inconclusive) Technically the member function 'Fred::b' can be const. [functionConst]\n", errout_str()); checkConst("class Fred {\n" "public:\n" " int x;\n" " void b() { a(); }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (performance, inconclusive) Technically the member function 'Fred::b' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::b' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); // static functions can't be const.. checkConst("class foo\n" @@ -3703,7 +3704,7 @@ class TestClass : public TestFixture { checkConst("class Fred {\n" " const std::string foo() const throw() { return \"\"; }\n" "};"); - ASSERT_EQUALS("[test.cpp:2]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:23]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); } void const2() { @@ -3720,7 +3721,7 @@ class TestClass : public TestFixture { " std::string s;\n" " void foo(std::string & a) { a = s; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'Fred::foo' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str()); // assignment to variable can't be const checkConst("class Fred {\n" @@ -3734,7 +3735,7 @@ class TestClass : public TestFixture { " std::string s;\n" " void foo(std::string & a, std::string & b) { a = s; b = s; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'Fred::foo' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str()); // assignment to variable, can't be const checkConst("class Fred {\n" @@ -3764,7 +3765,7 @@ class TestClass : public TestFixture { " int s;\n" " void foo(int * a) { *a = s; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'Fred::foo' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str()); // assignment to variable, can't be const checkConst("class Fred {\n" @@ -3778,7 +3779,7 @@ class TestClass : public TestFixture { " std::string s;\n" " void foo(std::string * a, std::string * b) { *a = s; *b = s; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'Fred::foo' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str()); // assignment to variable, can't be const checkConst("class Fred {\n" @@ -3808,14 +3809,14 @@ class TestClass : public TestFixture { " int getA();\n" "};\n" "int Fred::getA() { return a; }"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style, inconclusive) Technically the member function 'Fred::getA' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:5:11]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\n", errout_str()); checkConst("class Fred {\n" " std::string s;\n" " const std::string & foo();\n" "};\n" "const std::string & Fred::foo() { return \"\"; }"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:25] -> [test.cpp:5:27]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); // functions with a function call to a non-const member can't be const.. (#1305) checkConst("class Fred\n" @@ -3851,7 +3852,7 @@ class TestClass : public TestFixture { " void foo(std::string & a);\n" "};\n" "void Fred::foo(std::string & a) { a = s; }"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style, inconclusive) Technically the member function 'Fred::foo' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str()); // assignment to variable can't be const checkConst("class Fred {\n" @@ -3867,7 +3868,7 @@ class TestClass : public TestFixture { " void foo(std::string & a, std::string & b);\n" "};\n" "void Fred::foo(std::string & a, std::string & b) { a = s; b = s; }"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style, inconclusive) Technically the member function 'Fred::foo' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str()); // assignment to variable, can't be const checkConst("class Fred {\n" @@ -3899,7 +3900,7 @@ class TestClass : public TestFixture { " void foo(int * a);\n" "};\n" "void Fred::foo(int * a) { *a = s; }"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style, inconclusive) Technically the member function 'Fred::foo' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str()); // assignment to variable, can't be const checkConst("class Fred {\n" @@ -3915,7 +3916,7 @@ class TestClass : public TestFixture { " void foo(std::string * a, std::string * b);\n" "};\n" "void Fred::foo(std::string * a, std::string * b) { *a = s; *b = s; }"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style, inconclusive) Technically the member function 'Fred::foo' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str()); // assignment to variable, can't be const checkConst("class Fred {\n" @@ -3951,8 +3952,8 @@ class TestClass : public TestFixture { "void Fred::foo() { }" "void Fred::foo(std::string & a) { a = s; }" "void Fred::foo(const std::string & a) { s = a; }"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:7]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace).\n" - "[test.cpp:4] -> [test.cpp:7]: (style, inconclusive) Technically the member function 'Fred::foo' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n" + "[test.cpp:4:10] -> [test.cpp:7:32]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str()); // check functions with different or missing parameter names checkConst("class Fred {\n" @@ -3968,11 +3969,11 @@ class TestClass : public TestFixture { "void Fred::foo3(int a, int b) { }\n" "void Fred::foo4(int a, int b) { }\n" "void Fred::foo5(int, int) { }"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:9]: (performance, inconclusive) Technically the member function 'Fred::foo1' can be static (but you may consider moving to unnamed namespace).\n" - "[test.cpp:4] -> [test.cpp:10]: (performance, inconclusive) Technically the member function 'Fred::foo2' can be static (but you may consider moving to unnamed namespace).\n" - "[test.cpp:5] -> [test.cpp:11]: (performance, inconclusive) Technically the member function 'Fred::foo3' can be static (but you may consider moving to unnamed namespace).\n" - "[test.cpp:6] -> [test.cpp:12]: (performance, inconclusive) Technically the member function 'Fred::foo4' can be static (but you may consider moving to unnamed namespace).\n" - "[test.cpp:7] -> [test.cpp:13]: (performance, inconclusive) Technically the member function 'Fred::foo5' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::foo1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n" + "[test.cpp:4:10] -> [test.cpp:10:12]: (performance, inconclusive) Technically the member function 'Fred::foo2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n" + "[test.cpp:5:10] -> [test.cpp:11:12]: (performance, inconclusive) Technically the member function 'Fred::foo3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n" + "[test.cpp:6:10] -> [test.cpp:12:12]: (performance, inconclusive) Technically the member function 'Fred::foo4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n" + "[test.cpp:7:10] -> [test.cpp:13:12]: (performance, inconclusive) Technically the member function 'Fred::foo5' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); // check nested classes checkConst("class Fred {\n" @@ -3981,7 +3982,7 @@ class TestClass : public TestFixture { " int getA() { return a; }\n" " };\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\n", errout_str()); checkConst("class Fred {\n" " class A {\n" @@ -3990,7 +3991,7 @@ class TestClass : public TestFixture { " };\n" " int A::getA() { return a; }\n" "};"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13] -> [test.cpp:6:12]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\n", errout_str()); checkConst("class Fred {\n" " class A {\n" @@ -3999,7 +4000,7 @@ class TestClass : public TestFixture { " };\n" "};\n" "int Fred::A::getA() { return a; }"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:7]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13] -> [test.cpp:7:14]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\n", errout_str()); // check deeply nested classes checkConst("class Fred {\n" @@ -4012,8 +4013,8 @@ class TestClass : public TestFixture { " };\n" " };\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const.\n" - "[test.cpp:7]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const.\n" + ASSERT_EQUALS("[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\n" + "[test.cpp:7:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\n" , errout_str()); checkConst("class Fred {\n" @@ -4028,8 +4029,8 @@ class TestClass : public TestFixture { " };\n" " int B::getB() { return b; }\n" "};"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:11]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const.\n" - "[test.cpp:7] -> [test.cpp:9]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\n" + "[test.cpp:7:17] -> [test.cpp:9:16]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\n", errout_str()); checkConst("class Fred {\n" " class B {\n" @@ -4043,8 +4044,8 @@ class TestClass : public TestFixture { " int B::A::getA() { return a; }\n" " int B::getB() { return b; }\n" "};"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:11]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const.\n" - "[test.cpp:7] -> [test.cpp:10]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\n" + "[test.cpp:7:17] -> [test.cpp:10:15]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\n", errout_str()); checkConst("class Fred {\n" " class B {\n" @@ -4058,8 +4059,8 @@ class TestClass : public TestFixture { "};\n" "int Fred::B::A::getA() { return a; }\n" "int Fred::B::getB() { return b; }"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const.\n" - "[test.cpp:7] -> [test.cpp:11]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13] -> [test.cpp:12:14]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\n" + "[test.cpp:7:17] -> [test.cpp:11:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\n", errout_str()); } // operator< can often be const @@ -4068,7 +4069,7 @@ class TestClass : public TestFixture { " int a;\n" " bool operator<(const Fred &f) { return a < f.a; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'Fred::operator<' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::operator<' can be const. [functionConst]\n", errout_str()); } // operator<< @@ -4095,7 +4096,7 @@ class TestClass : public TestFixture { " std::cout << foo << 123;\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (style, inconclusive) Technically the member function 'Fred::x' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Fred::x' can be const. [functionConst]\n", errout_str()); } void constoperator3() { @@ -4110,7 +4111,7 @@ class TestClass : public TestFixture { " int array[10];\n" " int const & operator [] (unsigned int index) { return array[index]; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'Fred::operator[]' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (style, inconclusive) Technically the member function 'Fred::operator[]' can be const. [functionConst]\n", errout_str()); } void constoperator4() { @@ -4127,7 +4128,7 @@ class TestClass : public TestFixture { "public:\n" " operator const int*() { return &c; };\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::operatorconstint*' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint*' can be const. [functionConst]\n", errout_str()); // #2375 checkConst("struct Fred {\n" @@ -4158,14 +4159,14 @@ class TestClass : public TestFixture { "public:\n" " operator const int& () {return c}\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::operatorconstint&' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint&' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" " int c;\n" "public:\n" " operator int () {return c}\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::operatorint' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorint' can be const. [functionConst]\n", errout_str()); } void constoperator6() { // ticket #8669 @@ -4187,7 +4188,7 @@ class TestClass : public TestFixture { " return same;\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'A::foo' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\n", errout_str()); } void const6() { @@ -4203,7 +4204,7 @@ class TestClass : public TestFixture { "public:\n" " void foo() { }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("struct fast_string\n" "{\n" @@ -4240,7 +4241,7 @@ class TestClass : public TestFixture { "private:\n" " std::string m_strValue;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::strGetString' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:17]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\n", errout_str()); } void const9() { @@ -4300,7 +4301,7 @@ class TestClass : public TestFixture { "private:\n" " mutable int x;\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'A::foo' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\n", errout_str()); } void const13() { @@ -4314,8 +4315,8 @@ class TestClass : public TestFixture { " std::vector m_vec;\n" " std::pair m_pair;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::GetVec' can be const.\n" - "[test.cpp:5]: (style, inconclusive) Technically the member function 'A::GetPair' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:22]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\n" + "[test.cpp:5:27]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" "public:\n" @@ -4326,8 +4327,8 @@ class TestClass : public TestFixture { " std::vector m_vec;\n" " std::pair m_pair;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::GetVec' can be const.\n" - "[test.cpp:5]: (style, inconclusive) Technically the member function 'A::GetPair' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:30]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\n" + "[test.cpp:5:35]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); } void const14() { @@ -4339,7 +4340,7 @@ class TestClass : public TestFixture { "private:\n" " std::pair,double> m_pair;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::GetPair' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" "public:\n" @@ -4348,7 +4349,7 @@ class TestClass : public TestFixture { "private:\n" " std::pair,double> m_pair;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::GetPair' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" "public:\n" @@ -4368,7 +4369,7 @@ class TestClass : public TestFixture { "private:\n" " pair m_pair;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::GetPair' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:23]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("using namespace std;" "class A {\n" @@ -4378,7 +4379,7 @@ class TestClass : public TestFixture { "private:\n" " pair m_pair;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::GetPair' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("using namespace std;" "class A {\n" @@ -4398,7 +4399,7 @@ class TestClass : public TestFixture { "private:\n" " std::pair< int,std::vector > m_pair;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::GetPair' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" "public:\n" @@ -4407,7 +4408,7 @@ class TestClass : public TestFixture { "private:\n" " std::pair< int,std::vector > m_pair;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::GetPair' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" "public:\n" @@ -4427,7 +4428,7 @@ class TestClass : public TestFixture { "private:\n" " pair< vector, int > m_pair;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::GetPair' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("using namespace std;" "class A {\n" @@ -4437,7 +4438,7 @@ class TestClass : public TestFixture { "private:\n" " pair< vector, int > m_pair;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::GetPair' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:38]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("using namespace std;" "class A {\n" @@ -4456,7 +4457,7 @@ class TestClass : public TestFixture { "private:\n" " std::pair< std::vector,std::vector > m_pair;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::GetPair' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:53]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" "public:\n" @@ -4465,7 +4466,7 @@ class TestClass : public TestFixture { "private:\n" " std::pair< std::vector,std::vector > m_pair;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::GetPair' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:60]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" "public:\n" @@ -4485,7 +4486,7 @@ class TestClass : public TestFixture { "private:\n" " std::pair< std::pair < int, char > , int > m_pair;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::GetPair' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" "public:\n" @@ -4494,7 +4495,7 @@ class TestClass : public TestFixture { "private:\n" " std::pair< std::pair < int, char > , int > m_pair;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::GetPair' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" "public:\n" @@ -4513,7 +4514,7 @@ class TestClass : public TestFixture { "private:\n" " std::pair< int , std::pair < int, char > > m_pair;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::GetPair' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" "public:\n" @@ -4522,7 +4523,7 @@ class TestClass : public TestFixture { "private:\n" " std::pair< int , std::pair < int, char > > m_pair;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::GetPair' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" "public:\n" @@ -4542,7 +4543,7 @@ class TestClass : public TestFixture { "private:\n" " vector m_Vec;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::GetVec' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:18]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\n", errout_str()); checkConst("using namespace std;" "class A {\n" @@ -4552,7 +4553,7 @@ class TestClass : public TestFixture { "private:\n" " vector m_Vec;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::GetVec' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:25]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\n", errout_str()); checkConst("using namespace std;" "class A {\n" @@ -4579,7 +4580,7 @@ class TestClass : public TestFixture { "private:\n" " const int * x;\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'A::foo' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:18]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\n", errout_str()); } void const15() { @@ -4587,7 +4588,7 @@ class TestClass : public TestFixture { " unsigned long long int a;\n" " unsigned long long int getA() { return a; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'Fred::getA' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:28]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\n", errout_str()); // constructors can't be const.. checkConst("class Fred {\n" @@ -4640,7 +4641,7 @@ class TestClass : public TestFixture { "public:\n" " void set(int i) { x = i; }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (performance, inconclusive) Technically the member function 'Fred::set' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'Fred::set' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); } void const19() { @@ -4676,7 +4677,7 @@ class TestClass : public TestFixture { "public:\n" " list get() { return x; }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::get' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:23]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\n", errout_str()); checkConst("class Fred {\n" " std::list x;\n" @@ -4690,7 +4691,7 @@ class TestClass : public TestFixture { "public:\n" " std::list get() { return x; }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::get' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:36]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\n", errout_str()); } void const21() { @@ -4776,7 +4777,7 @@ class TestClass : public TestFixture { "private:\n" "std::string m_strVal;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::strGetString' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\n", errout_str()); checkConst("class A{\n" "public:\n" @@ -4786,7 +4787,7 @@ class TestClass : public TestFixture { "private:\n" "std::string m_strVal;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::strGetString1' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:19]: (style, inconclusive) Technically the member function 'A::strGetString1' can be const. [functionConst]\n", errout_str()); checkConst("class A{\n" "public:\n" @@ -4796,7 +4797,7 @@ class TestClass : public TestFixture { "private:\n" "std::vector m_strVec;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:8]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const. [functionConst]\n", errout_str()); checkConst("class A{\n" "public:\n" @@ -4806,7 +4807,7 @@ class TestClass : public TestFixture { "private:\n" "std::vector m_strVec;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:6]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const. [functionConst]\n", errout_str()); } void const26() { // ticket #1847 @@ -4825,7 +4826,7 @@ class TestClass : public TestFixture { " }\n" " float delays_[4];\n" "};"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Technically the member function 'DelayBase::swapSpecificDelays' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style, inconclusive) Technically the member function 'DelayBase::swapSpecificDelays' can be const. [functionConst]\n", errout_str()); } void const27() { // ticket #1882 @@ -4843,7 +4844,7 @@ class TestClass : public TestFixture { " return m_iRealVal / m_d;\n" " return dRet;\n" "};"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:9]: (style, inconclusive) Technically the member function 'A::dGetValue' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12] -> [test.cpp:9:12]: (style, inconclusive) Technically the member function 'A::dGetValue' can be const. [functionConst]\n", errout_str()); } void const28() { // ticket #1883 @@ -4880,7 +4881,7 @@ class TestClass : public TestFixture { " UnknownScope::x = x_;\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (performance, inconclusive) Technically the member function 'AA::vSetXPos' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:17]: (performance, inconclusive) Technically the member function 'AA::vSetXPos' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); } @@ -4920,7 +4921,7 @@ class TestClass : public TestFixture { " return a;\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:7]: (style, inconclusive) Technically the member function 'Derived::get' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:9]: (style, inconclusive) Technically the member function 'Derived::get' can be const. [functionConst]\n", errout_str()); checkConst("class Base1 {\n" "public:\n" @@ -4939,8 +4940,8 @@ class TestClass : public TestFixture { " return b;\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:11]: (style, inconclusive) Technically the member function 'Derived::getA' can be const.\n" - "[test.cpp:14]: (style, inconclusive) Technically the member function 'Derived::getB' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Derived::getA' can be const. [functionConst]\n" + "[test.cpp:14:9]: (style, inconclusive) Technically the member function 'Derived::getB' can be const. [functionConst]\n", errout_str()); checkConst("class Base {\n" "public:\n" @@ -4953,7 +4954,7 @@ class TestClass : public TestFixture { " return a;\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:8]: (style, inconclusive) Technically the member function 'Derived2::get' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:9]: (style, inconclusive) Technically the member function 'Derived2::get' can be const. [functionConst]\n", errout_str()); checkConst("class Base {\n" "public:\n" @@ -4968,7 +4969,7 @@ class TestClass : public TestFixture { " return a;\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:10]: (style, inconclusive) Technically the member function 'Derived4::get' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:9]: (style, inconclusive) Technically the member function 'Derived4::get' can be const. [functionConst]\n", errout_str()); // check for false positives checkConst("class Base {\n" @@ -5038,7 +5039,7 @@ class TestClass : public TestFixture { " int a;\n" " int get() { return a; }\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (style, inconclusive) Technically the member function 'Fred::get' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\n", errout_str()); } void const32() { @@ -5055,7 +5056,7 @@ class TestClass : public TestFixture { "public:\n" " void f(){}\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Either there is a missing 'override', or the member function 'derived::f' can be static.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Either there is a missing 'override', or the member function 'derived::f' can be static. [functionStatic]\n", errout_str()); } void const34() { // ticket #1964 @@ -5083,7 +5084,7 @@ class TestClass : public TestFixture { " int var;\n" " };\n" "}"); - ASSERT_EQUALS("[test.cpp:12]: (style, inconclusive) Technically the member function 'N::Derived::getResourceName' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:12:21]: (style, inconclusive) Technically the member function 'N::Derived::getResourceName' can be const. [functionConst]\n", errout_str()); checkConst("namespace N\n" "{\n" @@ -5095,7 +5096,7 @@ class TestClass : public TestFixture { " };\n" "}\n" "int N::Base::getResourceName() { return var; }"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:10]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:21] -> [test.cpp:10:14]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\n", errout_str()); checkConst("namespace N\n" "{\n" @@ -5110,7 +5111,7 @@ class TestClass : public TestFixture { "{\n" " int Base::getResourceName() { return var; }\n" "}"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:12]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:21] -> [test.cpp:12:19]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\n", errout_str()); checkConst("namespace N\n" "{\n" @@ -5123,7 +5124,7 @@ class TestClass : public TestFixture { "}\n" "using namespace N;\n" "int Base::getResourceName() { return var; }"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:11]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:21] -> [test.cpp:11:11]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\n", errout_str()); } void const36() { // ticket #2003 @@ -5150,7 +5151,7 @@ class TestClass : public TestFixture { "private:\n" " std::string m_str;\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (style, inconclusive) Technically the member function 'A::operator+' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:17]: (style, inconclusive) Technically the member function 'A::operator+' can be const. [functionConst]\n", errout_str()); checkConst("class Fred\n" "{\n" @@ -5164,7 +5165,7 @@ class TestClass : public TestFixture { " return (x == 0x11224488);\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:9]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:10]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const. [functionConst]\n", errout_str()); } void const38() { // ticket #2135 @@ -5308,7 +5309,7 @@ class TestClass : public TestFixture { "{\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:7]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10] -> [test.cpp:7:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("class Fred\n" "{\n" @@ -5322,7 +5323,7 @@ class TestClass : public TestFixture { "{\n" "}"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:10] -> [test.cpp:9:12]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("namespace NS {\n" " class Fred\n" @@ -5338,7 +5339,7 @@ class TestClass : public TestFixture { " }\n" "}"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:10]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:14] -> [test.cpp:10:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("namespace NS {\n" " class Fred\n" @@ -5354,7 +5355,7 @@ class TestClass : public TestFixture { "{\n" "}"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:14] -> [test.cpp:11:16]: (performance, inconclusive) Technically the member function 'NS::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("class Foo {\n" " class Fred\n" @@ -5370,7 +5371,7 @@ class TestClass : public TestFixture { "{\n" "}"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (performance, inconclusive) Technically the member function 'Foo::Fred::f' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:14] -> [test.cpp:11:17]: (performance, inconclusive) Technically the member function 'Foo::Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); } void const43() { // ticket 2377 @@ -5459,7 +5460,7 @@ class TestClass : public TestFixture { " };\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (performance, inconclusive) Technically the member function 'tools::WorkspaceControl::toGrid' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:13]: (performance, inconclusive) Technically the member function 'tools::WorkspaceControl::toGrid' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); } void const46() { // ticket 2663 @@ -5474,8 +5475,8 @@ class TestClass : public TestFixture { " }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Altren::fun1' can be static (but you may consider moving to unnamed namespace).\n" - "[test.cpp:7]: (performance, inconclusive) Technically the member function 'Altren::fun2' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (performance, inconclusive) Technically the member function 'Altren::fun1' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n" + "[test.cpp:7:9]: (performance, inconclusive) Technically the member function 'Altren::fun2' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); } void const47() { // ticket 2670 @@ -5486,7 +5487,7 @@ class TestClass : public TestFixture { " void bar() { foo(); }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("class Altren {\n" "public:\n" @@ -5495,8 +5496,8 @@ class TestClass : public TestFixture { " void bar() { foo(1); }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace).\n" - "[test.cpp:5]: (style, inconclusive) Technically the member function 'Altren::bar' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:8]: (performance, inconclusive) Technically the member function 'Altren::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n" + "[test.cpp:5:8]: (style, inconclusive) Technically the member function 'Altren::bar' can be const. [functionConst]\n", errout_str()); } void const48() { // ticket 2672 @@ -5586,7 +5587,7 @@ class TestClass : public TestFixture { "private:\n" " int bar;\n" "};"); - ASSERT_EQUALS("[test.cpp:2]: (performance, inconclusive) Technically the member function 'foo::DoSomething' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'foo::DoSomething' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); } void const53() { // ticket 3049 @@ -5630,7 +5631,7 @@ class TestClass : public TestFixture { " switch (x) { }\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("class A\n" "{\n" @@ -5670,7 +5671,7 @@ class TestClass : public TestFixture { "\n" " return RET_NOK;\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:9]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:24] -> [test.cpp:9:19]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("class MyObject {\n" "public:\n" @@ -5678,7 +5679,7 @@ class TestClass : public TestFixture { " for (int i = 0; i < 5; i++) { }\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); } void const57() { // tickets #2669 and #2477 @@ -5703,9 +5704,9 @@ class TestClass : public TestFixture { "private:\n" " MyGUI::IntCoord mCoordValue;\n" "};"); - TODO_ASSERT_EQUALS("[test.cpp:7]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace).\n" + TODO_ASSERT_EQUALS("[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n" "[test.cpp:15]: (style, inconclusive) Technically the member function 'SelectorControl::getSize' can be const.\n", - "[test.cpp:7]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + "[test.cpp:7:13]: (performance, inconclusive) Technically the member function 'MyGUI::types::TCoord::size' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("struct Foo {\n" " Bar b;\n" @@ -5736,8 +5737,8 @@ class TestClass : public TestFixture { " b.run();\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:2]: (performance, inconclusive) Technically the member function 'Bar::run' can be static (but you may consider moving to unnamed namespace).\n" - "[test.cpp:6]: (style, inconclusive) Technically the member function 'Foo::foo' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Bar::run' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n" + "[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Foo::foo' can be const. [functionConst]\n", errout_str()); } void const58() { @@ -5746,14 +5747,14 @@ class TestClass : public TestFixture { " f.clear();\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:2]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("struct MyObject {\n" " int foo(Foo f) {\n" " return f.length();\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:2]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("struct MyObject {\n" " Foo f;\n" @@ -5769,7 +5770,7 @@ class TestClass : public TestFixture { " return f.length();\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'MyObject::foo' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style, inconclusive) Technically the member function 'MyObject::foo' can be const. [functionConst]\n", errout_str()); } void const59() { // ticket #4646 @@ -5841,7 +5842,7 @@ class TestClass : public TestFixture { " inherited::set(inherited::Key(key));\n" " }\n" "};\n", dinit(CheckConstOptions, $.inconclusive = false)); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::GetAudioFrame' can be static.\n", + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:4:23]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::GetAudioFrame' can be static. [functionStatic]\n", errout_str()); } @@ -5885,7 +5886,7 @@ class TestClass : public TestFixture { " r.clear();\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'A::clear' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\n", errout_str()); checkConst("struct A {\n" " std::string s;\n" @@ -5894,7 +5895,7 @@ class TestClass : public TestFixture { " p->somefunction();\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'A::clear' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\n", errout_str()); checkConst("struct A {\n" " std::string s;\n" @@ -5903,7 +5904,7 @@ class TestClass : public TestFixture { " r.somefunction();\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'A::clear' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\n", errout_str()); } void const64() { @@ -5961,7 +5962,7 @@ class TestClass : public TestFixture { " const std::list>& get() { return m_test.m_list; }\n" " TestList> m_test;\n" "};"); - ASSERT_EQUALS("[test.cpp:8]: (style, inconclusive) Technically the member function 'Test::get' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:44]: (style, inconclusive) Technically the member function 'Test::get' can be const. [functionConst]\n", errout_str()); } void const68() { // #6471 @@ -6075,7 +6076,7 @@ class TestClass : public TestFixture { " int i{};\n" " S f() { return S{ &i }; }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:7]: (style, inconclusive) Technically the member function 'C::f' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\n", errout_str()); checkConst("struct S {\n" " explicit S(const int* p) : mp(p) {}\n" @@ -6085,7 +6086,7 @@ class TestClass : public TestFixture { " int i{};\n" " S f() { return S(&i); }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:7]: (style, inconclusive) Technically the member function 'C::f' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\n", errout_str()); checkConst("struct S {\n" " const int* mp{};\n" @@ -6094,7 +6095,7 @@ class TestClass : public TestFixture { " int i{};\n" " S f() { return S{ &i }; }\n" "};\n"); - TODO_ASSERT_EQUALS("[test.cpp:7]: (style, inconclusive) Technically the member function 'C::f' can be const.\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\n", "", errout_str()); checkConst("struct S {\n" " const int* mp{};\n" @@ -6103,7 +6104,7 @@ class TestClass : public TestFixture { " int i{};\n" " S f() { return { &i }; }\n" "};\n"); - TODO_ASSERT_EQUALS("[test.cpp:7]: (style, inconclusive) Technically the member function 'C::f' can be const.\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:7:7]: (style, inconclusive) Technically the member function 'C::f' can be const. [functionConst]\n", "", errout_str()); } void const73() { @@ -6127,7 +6128,7 @@ class TestClass : public TestFixture { "void S::f() {\n" " char* c = h->x[y];\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style, inconclusive) Technically the member function 'S::f' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\n", errout_str()); } void const74() { // #10671 @@ -6139,7 +6140,7 @@ class TestClass : public TestFixture { " for(std::vector::const_iterator it = m_str.begin(); it != m_str.end(); ++it) {;}\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (style, inconclusive) Technically the member function 'A::bar' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (style, inconclusive) Technically the member function 'A::bar' can be const. [functionConst]\n", errout_str()); // Don't crash checkConst("struct S {\n" @@ -6160,7 +6161,7 @@ class TestClass : public TestFixture { " if (N::i) {}\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("int i = 0;\n" "struct S {\n" @@ -6169,7 +6170,7 @@ class TestClass : public TestFixture { " if (::i) {}\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("namespace N {\n" " struct S {\n" @@ -6179,7 +6180,7 @@ class TestClass : public TestFixture { " }\n" " };\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'N::S::f' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14]: (style, inconclusive) Technically the member function 'N::S::f' can be const. [functionConst]\n", errout_str()); } void const76() { // #10825 @@ -6192,7 +6193,7 @@ class TestClass : public TestFixture { "void S::f(const T* t) {\n" " const_cast(t)->e();\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:7]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace).\n", + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:7:9]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); } @@ -6238,7 +6239,7 @@ class TestClass : public TestFixture { " return nullptr;\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace).\n", + ASSERT_EQUALS("[test.cpp:3:11]: (performance, inconclusive) Technically the member function 'A::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); } @@ -6269,10 +6270,10 @@ class TestClass : public TestFixture { "void S::n() {\n" " this->h();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:11]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace).\n" - "[test.cpp:5] -> [test.cpp:14]: (performance, inconclusive) Technically the member function 'S::h' can be static (but you may consider moving to unnamed namespace).\n" - "[test.cpp:6] -> [test.cpp:17]: (style, inconclusive) Technically the member function 'S::k' can be const.\n" - "[test.cpp:7] -> [test.cpp:21]: (performance, inconclusive) Technically the member function 'S::m' can be static (but you may consider moving to unnamed namespace).\n", + ASSERT_EQUALS("[test.cpp:4:10] -> [test.cpp:11:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n" + "[test.cpp:5:10] -> [test.cpp:14:9]: (performance, inconclusive) Technically the member function 'S::h' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n" + "[test.cpp:6:10] -> [test.cpp:17:9]: (style, inconclusive) Technically the member function 'S::k' can be const. [functionConst]\n" + "[test.cpp:7:10] -> [test.cpp:21:9]: (performance, inconclusive) Technically the member function 'S::m' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); } @@ -6286,7 +6287,7 @@ class TestClass : public TestFixture { " if (a->f()) {}\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:6]: (style, inconclusive) Technically the member function 'S::g' can be const.\n", + ASSERT_EQUALS("[test.cpp:6:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\n", errout_str()); checkConst("struct A {\n" // #11499 @@ -6301,7 +6302,7 @@ class TestClass : public TestFixture { " P p;\n" " void g() { p->f(); }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:11]: (style, inconclusive) Technically the member function 'S::g' can be const.\n", + ASSERT_EQUALS("[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\n", errout_str()); checkConst("struct A {\n" @@ -6316,7 +6317,7 @@ class TestClass : public TestFixture { " P p;\n" " void g() { p->f(1); }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:11]: (style, inconclusive) Technically the member function 'S::g' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:11:8]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\n", errout_str()); checkConst("struct A {\n" " void f(void*) const;\n" @@ -6333,7 +6334,7 @@ class TestClass : public TestFixture { " P p;\n" " std::vector g() { p->f(nullptr); return {}; }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:14]: (style, inconclusive) Technically the member function 'S::g' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:14:20]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\n", errout_str()); checkConst("struct A {\n" " void f();\n" @@ -6385,7 +6386,7 @@ class TestClass : public TestFixture { " A* a;\n" " void g() { a->f(A::E1); }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:7]: (style, inconclusive) Technically the member function 'F::g' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:10]: (style, inconclusive) Technically the member function 'F::g' can be const. [functionConst]\n", errout_str()); } void const82() { // #11513 @@ -6394,7 +6395,7 @@ class TestClass : public TestFixture { " void h(bool) const;\n" " void g() { h(i == 1); }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'S::g' can be const.\n", + ASSERT_EQUALS("[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\n", errout_str()); checkConst("struct S {\n" @@ -6402,7 +6403,7 @@ class TestClass : public TestFixture { " void h(int, int*) const;\n" " void g() { int a; h(i, &a); }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'S::g' can be const.\n", + ASSERT_EQUALS("[test.cpp:4:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\n", errout_str()); } @@ -6438,8 +6439,8 @@ class TestClass : public TestFixture { " T t(s);\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:8]: (style, inconclusive) Technically the member function 'C::f1' can be const.\n" - "[test.cpp:11]: (style, inconclusive) Technically the member function 'C::f2' can be const.\n", + ASSERT_EQUALS("[test.cpp:8:10]: (style, inconclusive) Technically the member function 'C::f1' can be const. [functionConst]\n" + "[test.cpp:11:10]: (style, inconclusive) Technically the member function 'C::f2' can be const. [functionConst]\n", errout_str()); } @@ -6491,7 +6492,7 @@ class TestClass : public TestFixture { "bool CheckB::f(const std::string& s) {\n" " return CheckA::test(s, mSettings, mTokenizer->isCPP());\n" "}\n"); - ASSERT_EQUALS("[test.cpp:15] -> [test.cpp:20]: (style, inconclusive) Technically the member function 'CheckB::f' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:15:10] -> [test.cpp:20:14]: (style, inconclusive) Technically the member function 'CheckB::f' can be const. [functionConst]\n", errout_str()); checkConst("void g(int&);\n" "struct S {\n" @@ -6510,7 +6511,7 @@ class TestClass : public TestFixture { " int j;\n" " void f() { h(j, s.g()); }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:9]: (style, inconclusive) Technically the member function 'T::f' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\n", errout_str()); checkConst("struct S {\n" " int& g() { return i; }\n" @@ -6534,7 +6535,7 @@ class TestClass : public TestFixture { " int j;\n" " void f() { h(j, &s.g()); }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:9]: (style, inconclusive) Technically the member function 'T::f' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f' can be const. [functionConst]\n", errout_str()); checkConst("struct S {\n" " int& g() { return i; }\n" @@ -6583,16 +6584,16 @@ class TestClass : public TestFixture { " char* k() { return (char*)p; }\n" " int* p;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Technically the member function 'S::f' can be const.\n" - "[test.cpp:3]: (style, inconclusive) Technically the member function 'S::g' can be const.\n" - "[test.cpp:4]: (style, inconclusive) Technically the member function 'S::h' can be const.\n", + ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\n" + "[test.cpp:3:16]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\n" + "[test.cpp:4:16]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\n", errout_str()); checkConst("struct S {\n" " bool f() { return p != nullptr; }\n" " std::shared_ptr p;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Technically the member function 'S::f' can be const.\n", + ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\n", errout_str()); } @@ -6605,7 +6606,7 @@ class TestClass : public TestFixture { " if (i && b)\n" " f(false);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (style, inconclusive) Technically the member function 'S::f' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10] -> [test.cpp:5:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\n", errout_str()); checkConst("struct S {\n" " void f(int& r);\n" @@ -6631,8 +6632,8 @@ class TestClass : public TestFixture { " return 0;\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'S::f' can be const.\n" - "[test.cpp:8]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace).\n", + ASSERT_EQUALS("[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\n" + "[test.cpp:8:9]: (performance, inconclusive) Technically the member function 'S::g' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("class C {\n" // #11653 @@ -6643,7 +6644,7 @@ class TestClass : public TestFixture { " if (b)\n" " f(false);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (performance, inconclusive) Technically the member function 'C::f' can be static (but you may consider moving to unnamed namespace).\n", + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:5:9]: (performance, inconclusive) Technically the member function 'C::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); } @@ -6658,8 +6659,8 @@ class TestClass : public TestFixture { " void f1() { C c = C{ &s }; }\n" " void f2() { C c = C{ s }; }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:8]: (style, inconclusive) Technically the member function 'T::f1' can be const.\n" - "[test.cpp:9]: (style, inconclusive) Technically the member function 'T::f2' can be const.\n", + ASSERT_EQUALS("[test.cpp:8:10]: (style, inconclusive) Technically the member function 'T::f1' can be const. [functionConst]\n" + "[test.cpp:9:10]: (style, inconclusive) Technically the member function 'T::f2' can be const. [functionConst]\n", errout_str()); } @@ -6701,8 +6702,8 @@ class TestClass : public TestFixture { " }\n" " std::map m;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Technically the member function 'S::f' can be const.\n" - "[test.cpp:5]: (style, inconclusive) Technically the member function 'S::g' can be const.\n", + ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\n" + "[test.cpp:5:10]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\n", errout_str()); } @@ -6733,7 +6734,7 @@ class TestClass : public TestFixture { " bool g() override { return b; }\n" " bool b;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Either there is a missing 'override', or the member function 'S::f' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Either there is a missing 'override', or the member function 'S::f' can be const. [functionConst]\n", errout_str()); checkConst("struct B;\n" // #13382 "struct S : B {\n" @@ -6771,16 +6772,16 @@ class TestClass : public TestFixture { " r = 0;\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'S::f' can be const.\n" - "[test.cpp:7]: (style, inconclusive) Technically the member function 'S::g' can be const.\n" - "[test.cpp:11]: (style, inconclusive) Technically the member function 'S::h' can be const.\n", + ASSERT_EQUALS("[test.cpp:3:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\n" + "[test.cpp:7:9]: (style, inconclusive) Technically the member function 'S::g' can be const. [functionConst]\n" + "[test.cpp:11:10]: (style, inconclusive) Technically the member function 'S::h' can be const. [functionConst]\n", errout_str()); checkConst("struct B { std::string s; };\n" "struct D : B {\n" " bool f(std::string::iterator it) { return it == B::s.begin(); }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'D::f' can be const.\n", + ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'D::f' can be const. [functionConst]\n", errout_str()); } @@ -6864,8 +6865,8 @@ class TestClass : public TestFixture { " return foo3();\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:11]: (performance, inconclusive) Technically the member function 'Foo::bar3' can be static (but you may consider moving to unnamed namespace).\n" - "[test.cpp:14]: (performance, inconclusive) Technically the member function 'Foo::bar4' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:11:9]: (performance, inconclusive) Technically the member function 'Foo::bar3' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n" + "[test.cpp:14:9]: (performance, inconclusive) Technically the member function 'Foo::bar4' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); } void const_passThisToMemberOfOtherClass() { @@ -6883,7 +6884,7 @@ class TestClass : public TestFixture { " f.foo();\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:2]: (performance, inconclusive) Technically the member function 'Foo::foo' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Foo::foo' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("struct A;\n" // #5839 - operator() "struct B {\n" @@ -6951,25 +6952,25 @@ class TestClass : public TestFixture { "class Fred {\n" " void nextA() { return ++a; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("int a;\n" "class Fred {\n" " void nextA() { return --a; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("int a;\n" "class Fred {\n" " void nextA() { return a++; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("int a;\n" "class Fred {\n" " void nextA() { return a--; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("struct S {\n" // #10077 " int i{};\n" @@ -7015,31 +7016,31 @@ class TestClass : public TestFixture { "class Fred {\n" " void nextA() { return a=1; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("int a;\n" "class Fred {\n" " void nextA() { return a-=1; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("int a;\n" "class Fred {\n" " void nextA() { return a+=1; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("int a;\n" "class Fred {\n" " void nextA() { return a*=-1; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("int a;\n" "class Fred {\n" " void nextA() { return a/=-2; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); } void constassign2() { @@ -7071,31 +7072,31 @@ class TestClass : public TestFixture { "class Fred {\n" " void nextA() { return s.a=1; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("struct A { int a; } s;\n" "class Fred {\n" " void nextA() { return s.a-=1; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("struct A { int a; } s;\n" "class Fred {\n" " void nextA() { return s.a+=1; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("struct A { int a; } s;\n" "class Fred {\n" " void nextA() { return s.a*=-1; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("struct A { int a; } s;\n" "class Fred {\n" " void nextA() { return s.a/=-2; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("struct A { int a; };\n" "class Fred {\n" @@ -7163,25 +7164,25 @@ class TestClass : public TestFixture { "class Fred {\n" " void nextA() { return ++a[0]; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("int a[2];\n" "class Fred {\n" " void nextA() { return --a[0]; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("int a[2];\n" "class Fred {\n" " void nextA() { return a[0]++; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("int a[2];\n" "class Fred {\n" " void nextA() { return a[0]--; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); } void constassignarray() { @@ -7219,31 +7220,31 @@ class TestClass : public TestFixture { "class Fred {\n" " void nextA() { return a[0]=1; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("int a[2];\n" "class Fred {\n" " void nextA() { return a[0]-=1; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("int a[2];\n" "class Fred {\n" " void nextA() { return a[0]+=1; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("int a[2];\n" "class Fred {\n" " void nextA() { return a[0]*=-1; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst("int a[2];\n" "class Fred {\n" " void nextA() { return a[0]/=-2; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); } // return pointer/reference => not const @@ -7286,8 +7287,8 @@ class TestClass : public TestFixture { " void f() const { };\n" " void a() { f(); };\n" "};"); - ASSERT_EQUALS("[test.cpp:2]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace).\n" - "[test.cpp:3]: (style, inconclusive) Technically the member function 'Fred::a' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (performance, inconclusive) Technically the member function 'Fred::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n" + "[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::a' can be const. [functionConst]\n", errout_str()); // ticket #1593 checkConst("class A\n" @@ -7297,7 +7298,7 @@ class TestClass : public TestFixture { " A(){}\n" " unsigned int GetVecSize() {return m_v.size();}\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (style, inconclusive) Technically the member function 'A::GetVecSize' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:17]: (style, inconclusive) Technically the member function 'A::GetVecSize' can be const. [functionConst]\n", errout_str()); checkConst("class A\n" "{\n" @@ -7306,7 +7307,7 @@ class TestClass : public TestFixture { " A(){}\n" " bool GetVecEmpty() {return m_v.empty();}\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:9]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const. [functionConst]\n", errout_str()); } void constVirtualFunc() { @@ -7318,7 +7319,7 @@ class TestClass : public TestFixture { " B() : b(0) { }\n" " int func() { return b; }\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (style, inconclusive) Technically the member function 'B::func' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\n", errout_str()); checkConst("class A { };\n" "class B : public A {\n" @@ -7328,7 +7329,7 @@ class TestClass : public TestFixture { " int func();\n" "};\n" "int B::func() { return b; }"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:8]: (style, inconclusive) Technically the member function 'B::func' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:8] -> [test.cpp:8:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\n", errout_str()); // base class has no virtual function checkConst("class A {\n" @@ -7341,7 +7342,7 @@ class TestClass : public TestFixture { " B() : b(0) { }\n" " int func() { return b; }\n" "};"); - ASSERT_EQUALS("[test.cpp:9]: (style, inconclusive) Technically the member function 'B::func' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" "public:\n" @@ -7354,7 +7355,7 @@ class TestClass : public TestFixture { " int func();\n" "};\n" "int B::func() { return b; }"); - ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:11]: (style, inconclusive) Technically the member function 'B::func' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:9] -> [test.cpp:11:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\n", errout_str()); // base class has virtual function checkConst("class A {\n" @@ -7414,9 +7415,9 @@ class TestClass : public TestFixture { " C() : c(0) { }\n" " int func() { return c; }\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (style, inconclusive) Technically the member function 'A::func' can be const.\n" - "[test.cpp:11]: (style, inconclusive) Technically the member function 'B::func' can be const.\n" - "[test.cpp:17]: (style, inconclusive) Technically the member function 'C::func' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\n" + "[test.cpp:11:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\n" + "[test.cpp:17:9]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" " int a;\n" @@ -7439,9 +7440,9 @@ class TestClass : public TestFixture { " int func();\n" "};\n" "int C::func() { return c; }"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:7]: (style, inconclusive) Technically the member function 'A::func' can be const.\n" - "[test.cpp:12] -> [test.cpp:14]: (style, inconclusive) Technically the member function 'B::func' can be const.\n" - "[test.cpp:19] -> [test.cpp:21]: (style, inconclusive) Technically the member function 'C::func' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\n" + "[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\n" + "[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\n", errout_str()); // base class has virtual function checkConst("class A {\n" @@ -7506,9 +7507,9 @@ class TestClass : public TestFixture { " Z(int x, int y, int z) : Y(x, y), z(z) { }\n" " int getZ() { return z; }\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (style, inconclusive) Technically the member function 'X::getX' can be const.\n" - "[test.cpp:11]: (style, inconclusive) Technically the member function 'Y::getY' can be const.\n" - "[test.cpp:17]: (style, inconclusive) Technically the member function 'Z::getZ' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\n" + "[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\n" + "[test.cpp:17:9]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\n", errout_str()); checkConst("class X {\n" " int x;\n" @@ -7531,9 +7532,9 @@ class TestClass : public TestFixture { " int getZ();\n" "};\n" "int Z::getZ() { return z; }"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:7]: (style, inconclusive) Technically the member function 'X::getX' can be const.\n" - "[test.cpp:12] -> [test.cpp:14]: (style, inconclusive) Technically the member function 'Y::getY' can be const.\n" - "[test.cpp:19] -> [test.cpp:21]: (style, inconclusive) Technically the member function 'Z::getZ' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\n" + "[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\n" + "[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\n", errout_str()); } void constIfCfg() { @@ -7547,7 +7548,7 @@ class TestClass : public TestFixture { "};"; checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'foo::f' can be static (but you may consider moving to unnamed namespace).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (performance, inconclusive) Technically the member function 'foo::f' can be static (but you may consider moving to unnamed namespace). [functionStatic]\n", errout_str()); checkConst(code, dinit(CheckConstOptions, $.s = &settings0, $.inconclusive = false)); // TODO: Set inconclusive to true (preprocess it) ASSERT_EQUALS("", errout_str()); @@ -7589,7 +7590,7 @@ class TestClass : public TestFixture { " return y[1][6];\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:10]: (style, inconclusive) Technically the member function 'foo::c' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:7]: (style, inconclusive) Technically the member function 'foo::c' can be const. [functionConst]\n", errout_str()); } void constRangeBasedFor() { // #5514 @@ -7609,7 +7610,7 @@ class TestClass : public TestFixture { " foo(e);\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:8]: (style, inconclusive) Technically the member function 'Fred::f2' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:10]: (style, inconclusive) Technically the member function 'Fred::f2' can be const. [functionConst]\n", errout_str()); } void const_shared_ptr() { // #8674 @@ -7629,7 +7630,7 @@ class TestClass : public TestFixture { "public:\n" " const char *const *data;\n" " const char *const *getData() { return data; }\n}"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::getData' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:24]: (style, inconclusive) Technically the member function 'Fred::getData' can be const. [functionConst]\n", errout_str()); } void constTrailingReturnType() { // #9814 @@ -7676,7 +7677,7 @@ class TestClass : public TestFixture { "void S::f() {\n" " std::vector::const_iterator end = std.end();\n" "}\n", dinit(CheckConstOptions, $.s = &s)); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (style, inconclusive) Technically the member function 'S::f' can be const.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10] -> [test.cpp:6:9]: (style, inconclusive) Technically the member function 'S::f' can be const. [functionConst]\n", errout_str()); } #define checkInitializerListOrder(...) checkInitializerListOrder_(__FILE__, __LINE__, __VA_ARGS__) @@ -7696,16 +7697,16 @@ class TestClass : public TestFixture { "public:\n" " Fred() : c(0), b(0), a(0) { }\n" "};"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list.\n" - "[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\n" + "[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\n", errout_str()); checkInitializerListOrder("class Fred {\n" " int a, b, c;\n" "public:\n" " Fred() : c{0}, b{0}, a{0} { }\n" "};"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list.\n" - "[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\n" + "[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\n", errout_str()); checkInitializerListOrder("struct S {\n" " S() : b(a = 1) {}\n" @@ -7745,7 +7746,7 @@ class TestClass : public TestFixture { " B b;\n" " const A a;\n" "};"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5]: (style, inconclusive) Member variable 'C::b' uses an uninitialized argument 'a' due to the order of declarations.\n", + ASSERT_EQUALS("[test.cpp:4:11] -> [test.cpp:5:7]: (style, inconclusive) Member variable 'C::b' uses an uninitialized argument 'a' due to the order of declarations. [initializerList]\n", errout_str()); checkInitializerListOrder("struct S {\n" @@ -7810,7 +7811,7 @@ class TestClass : public TestFixture { " int a;\n" " int b;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style, inconclusive) Member variable 'Foo::a' uses an uninitialized argument 'b' due to the order of declarations.\n", + ASSERT_EQUALS("[test.cpp:3:20] -> [test.cpp:4:9]: (style, inconclusive) Member variable 'Foo::a' uses an uninitialized argument 'b' due to the order of declarations. [initializerList]\n", errout_str()); checkInitializerListOrder("struct S { double d = 0; };\n" // #12730 @@ -7858,7 +7859,7 @@ class TestClass : public TestFixture { " std::string s;\n" " Fred() { a = 0; s = \"foo\"; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance) Variable 's' is assigned in constructor body. Consider performing initialization in initialization list.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:21]: (performance) Variable 's' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\n", errout_str()); checkInitializationListUsage("class Fred {\n" " std::string& s;\n" // Message is invalid for references, since their initialization in initializer list is required anyway and behaves different from assignment (#5004) @@ -7870,35 +7871,35 @@ class TestClass : public TestFixture { " std::vector v;\n" " Fred() { v = unknown; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance) Variable 'v' is assigned in constructor body. Consider performing initialization in initialization list.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (performance) Variable 'v' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\n", errout_str()); checkInitializationListUsage("class C { std::string s; };\n" "class Fred {\n" " C c;\n" " Fred() { c = unknown; }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\n", errout_str()); checkInitializationListUsage("class C;\n" "class Fred {\n" " C c;\n" " Fred() { c = unknown; }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\n", errout_str()); checkInitializationListUsage("class C;\n" "class Fred {\n" " C c;\n" " Fred(Fred const & other) { c = other.c; }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:32]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\n", errout_str()); checkInitializationListUsage("class C;\n" "class Fred {\n" " C c;\n" " Fred(Fred && other) { c = other.c; }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:27]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\n", errout_str()); checkInitializationListUsage("class C;\n" "class Fred {\n" @@ -7952,7 +7953,7 @@ class TestClass : public TestFixture { " std::string a;\n" " Fred() { a = foo(); }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (performance) Variable 'a' is assigned in constructor body. Consider performing initialization in initialization list.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (performance) Variable 'a' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\n", errout_str()); checkInitializationListUsage("class Fred {\n" // #4332 " static std::string s;\n" @@ -8059,14 +8060,14 @@ class TestClass : public TestFixture { " Fred() : i(i) {\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (error) Member variable 'i' is initialized by itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\n", errout_str()); checkSelfInitialization("class Fred {\n" " int i;\n" " Fred() : i{i} {\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (error) Member variable 'i' is initialized by itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\n", errout_str()); checkSelfInitialization("class Fred {\n" " int i;\n" @@ -8074,7 +8075,7 @@ class TestClass : public TestFixture { "};\n" "Fred::Fred() : i(i) {\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Member variable 'i' is initialized by itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:14]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\n", errout_str()); checkSelfInitialization("class A {\n" // #10427 "public:\n" @@ -8082,7 +8083,7 @@ class TestClass : public TestFixture { "private:\n" " int _x;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Member variable '_x' is initialized by itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\n", errout_str()); checkSelfInitialization("class A {\n" "public:\n" @@ -8090,14 +8091,14 @@ class TestClass : public TestFixture { "private:\n" " int _x;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Member variable '_x' is initialized by itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:23]: (error) Member variable '_x' is initialized by itself. [selfInitialization]\n", errout_str()); checkSelfInitialization("class Fred {\n" " std::string s;\n" " Fred() : s(s) {\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (error) Member variable 's' is initialized by itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (error) Member variable 's' is initialized by itself. [selfInitialization]\n", errout_str()); checkSelfInitialization("class Fred {\n" " int x;\n" @@ -8171,21 +8172,21 @@ class TestClass : public TestFixture { "};\n" "A::A()\n" "{f();}"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (style) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:2] -> [test.cpp:3:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used. [virtualCallInConstructor]\n", errout_str()); checkVirtualFunctionCall("class A {\n" " virtual int f();\n" " A() {f();}\n" "};\n" "int A::f() { return 1; }"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:2:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\n", errout_str()); checkVirtualFunctionCall("class A : B {\n" " int f() override;\n" " A() {f();}\n" "};\n" "int A::f() { return 1; }"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:2:9]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\n", errout_str()); checkVirtualFunctionCall("class B {\n" " virtual int f() = 0;\n" @@ -8239,7 +8240,7 @@ class TestClass : public TestFixture { " auto d = dynamic_cast(Src);\n" " i = d.i;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:13] -> [test.cpp:9]: (style) Virtual function 'Copy' is called from copy constructor 'Derived(const Derived&Src)' at line 13. Dynamic binding is not used.\n", + ASSERT_EQUALS("[test.cpp:13:5] -> [test.cpp:9:10]: (style) Virtual function 'Copy' is called from copy constructor 'Derived(const Derived&Src)' at line 13. Dynamic binding is not used. [virtualCallInConstructor]\n", errout_str()); checkVirtualFunctionCall("struct B {\n" @@ -8258,7 +8259,7 @@ class TestClass : public TestFixture { " B() { (f)(); }\n" " virtual void f() {}\n" "};\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Virtual function 'f' is called from constructor 'B()' at line 2. Dynamic binding is not used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:3:18]: (style) Virtual function 'f' is called from constructor 'B()' at line 2. Dynamic binding is not used. [virtualCallInConstructor]\n", errout_str()); checkVirtualFunctionCall("class S {\n" // don't crash " ~S();\n" @@ -8288,7 +8289,7 @@ class TestClass : public TestFixture { "};\n" "A::A()\n" "{pure();}"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\n", errout_str()); checkVirtualFunctionCall("class A\n" "{\n" @@ -8298,7 +8299,7 @@ class TestClass : public TestFixture { "};\n" "A::A():m(A::pure())\n" "{}"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:13] -> [test.cpp:3:17]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\n", errout_str()); checkVirtualFunctionCall("namespace N {\n" " class A\n" @@ -8309,7 +8310,7 @@ class TestClass : public TestFixture { " };\n" "}\n" "N::A::A() : m(N::A::pure()) {}\n"); - ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:4]: (warning) Call of pure virtual function 'pure' in constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:21] -> [test.cpp:4:19]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\n", errout_str()); checkVirtualFunctionCall("class A\n" " {\n" @@ -8319,7 +8320,7 @@ class TestClass : public TestFixture { "};\n" "A::~A()\n" "{pure();}"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in destructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\n", errout_str()); checkVirtualFunctionCall("class A\n" " {\n" @@ -8330,7 +8331,7 @@ class TestClass : public TestFixture { "};\n" "A::A()\n" "{nonpure();}"); - ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:5] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\n", errout_str()); checkVirtualFunctionCall("class A\n" " {\n" @@ -8342,7 +8343,7 @@ class TestClass : public TestFixture { "};\n" "A::A():m(nonpure())\n" "{}"); - TODO_ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:5] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in constructor.\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\n", "", errout_str()); checkVirtualFunctionCall("class A\n" " {\n" @@ -8354,7 +8355,7 @@ class TestClass : public TestFixture { "};\n" "A::~A()\n" "{nonpure();}"); - ASSERT_EQUALS("[test.cpp:10] -> [test.cpp:5] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in destructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\n", errout_str()); checkVirtualFunctionCall("class A\n" "{\n" @@ -8363,7 +8364,7 @@ class TestClass : public TestFixture { "};\n" "A::A(bool b)\n" "{if (b) pure();}"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\n", errout_str()); checkVirtualFunctionCall("class A\n" "{\n" @@ -8373,7 +8374,7 @@ class TestClass : public TestFixture { "};\n" "A::~A()\n" "{if (b) pure();}"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in destructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\n", errout_str()); // #5831 checkVirtualFunctionCall("class abc {\n" @@ -8511,7 +8512,7 @@ class TestClass : public TestFixture { void override1() { checkOverride("class Base { virtual void f(); };\n" "class Derived : Base { virtual void f(); };"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:2]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:27] -> [test.cpp:2:37]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\n", errout_str()); checkOverride("class Base { virtual void f(); };\n" "class Derived : Base { virtual void f() override; };"); @@ -8531,7 +8532,7 @@ class TestClass : public TestFixture { " auto foo( ) const -> size_t { return 0; }\n" " auto bar( ) const -> size_t override { return 0; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:8]: (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:18] -> [test.cpp:8:10]: (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\n", errout_str()); checkOverride("namespace Test {\n" " class C {\n" @@ -8543,7 +8544,7 @@ class TestClass : public TestFixture { "public:\n" " ~C();\n" "};"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:9]: (style) The destructor '~C' overrides a destructor in a base class but is not marked with a 'override' specifier.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:18] -> [test.cpp:9:6]: (style) The destructor '~C' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\n", errout_str()); checkOverride("struct Base {\n" " virtual void foo();\n" @@ -8563,7 +8564,7 @@ class TestClass : public TestFixture { " virtual int f(int i) const;\n" " };\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:6]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17] -> [test.cpp:6:21]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\n", errout_str()); checkOverride("struct A {\n" " virtual void f(int);\n" @@ -8579,7 +8580,7 @@ class TestClass : public TestFixture { "struct D : A {\n" " void f(int);\n" "};\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\n", errout_str()); checkOverride("struct A {\n" " virtual void f(char, int);\n" @@ -8587,7 +8588,7 @@ class TestClass : public TestFixture { "struct D : A {\n" " void f(char, int);\n" "};\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\n", errout_str()); checkOverride("struct A {\n" " virtual void f(char, int);\n" @@ -8611,7 +8612,7 @@ class TestClass : public TestFixture { "struct D : A {\n" " void f(char c = '\\0', int);\n" "};\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\n", errout_str()); checkOverride("struct A {\n" " virtual void f(char c, std::vector);\n" @@ -8635,7 +8636,7 @@ class TestClass : public TestFixture { "struct D : A {\n" " void f(char c, std::vector w = {});\n" "};\n"); - TODO_ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier.\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:2:18] -> [test.cpp:5:8]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\n", "", errout_str()); checkOverride("struct T {};\n" // #10920 "struct B {\n" @@ -8655,7 +8656,7 @@ class TestClass : public TestFixture { "struct TPtr : public SPtr {\n" " T* operator->() const { return (T*)p; }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:8]: (style) The function 'operator->' overrides a function in a base class but is not marked with a 'override' specifier.\n", + ASSERT_EQUALS("[test.cpp:3:16] -> [test.cpp:8:8]: (style) The function 'operator->' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\n", errout_str()); checkOverride("class Base {\n" // #12131 @@ -8666,7 +8667,7 @@ class TestClass : public TestFixture { " return arg * 2;\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (style) The function 'Calculate' overrides a function in a base class but is not marked with a 'override' specifier.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17] -> [test.cpp:5:9]: (style) The function 'Calculate' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\n", errout_str()); checkOverride("struct S {\n" // #12439 " virtual ~S() = default;\n" @@ -8674,7 +8675,7 @@ class TestClass : public TestFixture { "struct D : S {\n" " ~D() {}\n" "};\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (style) The destructor '~D' overrides a destructor in a base class but is not marked with a 'override' specifier.\n", + ASSERT_EQUALS("[test.cpp:2:14] -> [test.cpp:5:6]: (style) The destructor '~D' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\n", errout_str()); } @@ -8714,13 +8715,13 @@ class TestClass : public TestFixture { "struct D : B {\n" " int f() override { return B::f(); }\n" "};"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:3]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\n", errout_str()); checkUselessOverride("struct B { virtual void f(); };\n" "struct D : B {\n" " void f() override { B::f(); }\n" "};"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:3]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:25] -> [test.cpp:3:10]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\n", errout_str()); checkUselessOverride("struct B { virtual int f() = 0; };\n" "int B::f() { return 5; }\n" @@ -8733,7 +8734,7 @@ class TestClass : public TestFixture { "struct D : B {\n" " int f(int i) override { return B::f(i); }\n" "};"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:3]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\n", errout_str()); checkUselessOverride("struct B { virtual int f(int i); };\n" "struct D : B {\n" @@ -8812,8 +8813,8 @@ class TestClass : public TestFixture { " int h(int j, int i) override { return i + j; }\n" " int j(int i, int j) override { return i + j; }\n" "};"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:9]: (style) The function 'g' overrides a function in a base class but is identical to the overridden function\n" - "[test.cpp:5] -> [test.cpp:11]: (style) The function 'j' overrides a function in a base class but is identical to the overridden function\n", + ASSERT_EQUALS("[test.cpp:3:17] -> [test.cpp:9:9]: (style) The function 'g' overrides a function in a base class but is identical to the overridden function [uselessOverride]\n" + "[test.cpp:5:17] -> [test.cpp:11:9]: (style) The function 'j' overrides a function in a base class but is identical to the overridden function [uselessOverride]\n", errout_str()); checkUselessOverride("struct B : std::exception {\n" @@ -8901,7 +8902,7 @@ class TestClass : public TestFixture { void unsafeClassRefMember() { checkUnsafeClassRefMember("class C { C(const std::string &s) : s(s) {} const std::string &s; };"); - ASSERT_EQUALS("[test.cpp:1]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:37]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues. [unsafeClassRefMember]\n", errout_str()); } @@ -9098,10 +9099,10 @@ class TestClass : public TestFixture { void ctuOneDefinitionRule() { ctu({"class C { C() { std::cout << 0; } };", "class C { C() { std::cout << 1; } };"}); - ASSERT_EQUALS("[1.cpp:1] -> [0.cpp:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C'\n", errout_str()); + ASSERT_EQUALS("[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\n", errout_str()); ctu({"class C { C(); }; C::C() { std::cout << 0; }", "class C { C(); }; C::C() { std::cout << 1; }"}); - ASSERT_EQUALS("[1.cpp:1] -> [0.cpp:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C'\n", errout_str()); + ASSERT_EQUALS("[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\n", errout_str()); ctu({"class C { C() {} };\n", "class C { C() {} };\n"}); ASSERT_EQUALS("", errout_str()); @@ -9164,8 +9165,8 @@ class TestClass : public TestFixture { " std::string getS() const { return s; }\n" " unknown_t f() { return; }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:6]: (performance) Function 'getT()' should return member 't' by const reference.\n" - "[test.cpp:8]: (performance) Function 'getS()' should return member 's' by const reference.\n", + ASSERT_EQUALS("[test.cpp:6:7]: (performance) Function 'getT()' should return member 't' by const reference. [returnByReference]\n" + "[test.cpp:8:17]: (performance) Function 'getS()' should return member 's' by const reference. [returnByReference]\n", errout_str()); checkReturnByReference("struct B {\n" // #12608 @@ -9219,8 +9220,8 @@ class TestClass : public TestFixture { " }\n" " S1* mS1;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:6]: (performance) Function 'get1()' should return member 'str' by const reference.\n" - "[test.cpp:9]: (performance) Function 'get2()' should return member 'strT' by const reference.\n", + ASSERT_EQUALS("[test.cpp:6:17]: (performance) Function 'get1()' should return member 'str' by const reference. [returnByReference]\n" + "[test.cpp:9:17]: (performance) Function 'get2()' should return member 'strT' by const reference. [returnByReference]\n", errout_str()); checkReturnByReference("struct S { std::string str; };\n" // #13059 @@ -9237,7 +9238,7 @@ class TestClass : public TestFixture { " }\n" " T t;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:10]: (performance) Function 'get2()' should return member 'str' by const reference.\n", + ASSERT_EQUALS("[test.cpp:10:17]: (performance) Function 'get2()' should return member 'str' by const reference. [returnByReference]\n", errout_str()); } }; diff --git a/test/testother.cpp b/test/testother.cpp index bab8aad84ac..c3b850b5e5d 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -36,6 +36,7 @@ class TestOther : public TestFixture { /*const*/ Settings _settings = settingsBuilder().library("std.cfg").build(); void run() override { + mNewTemplate = true; TEST_CASE(emptyBrackets); TEST_CASE(zeroDiv1); @@ -396,7 +397,7 @@ class TestOther : public TestFixture { check("void foo() {\n" " cout << 42 / (int)0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (error) Division by zero. [zerodiv]\n", errout_str()); } void zeroDiv2() { @@ -416,27 +417,27 @@ class TestOther : public TestFixture { check("int foo(int i) {\n" " return i / 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (error) Division by zero. [zerodiv]\n", errout_str()); check("int foo(int i) {\n" " return i % 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (error) Division by zero. [zerodiv]\n", errout_str()); check("void foo(int& i) {\n" " i /= 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:7]: (error) Division by zero. [zerodiv]\n", errout_str()); check("void foo(int& i) {\n" " i %= 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:7]: (error) Division by zero. [zerodiv]\n", errout_str()); check("uint8_t foo(uint8_t i) {\n" " return i / 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (error) Division by zero. [zerodiv]\n", errout_str()); } void zeroDiv4() { @@ -455,7 +456,7 @@ class TestOther : public TestFixture { "{\n" " long a = b / 0x0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15]: (error) Division by zero. [zerodiv]\n", errout_str()); check("void f()\n" "{\n" @@ -466,7 +467,7 @@ class TestOther : public TestFixture { "{\n" " long a = b / 0L;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15]: (error) Division by zero. [zerodiv]\n", errout_str()); check("void f()\n" "{\n" @@ -477,7 +478,7 @@ class TestOther : public TestFixture { "{\n" " long a = b / 0ul;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15]: (error) Division by zero. [zerodiv]\n", errout_str()); // Don't warn about floating points (gcc doesn't warn either) // and floating points are handled differently than integers. @@ -504,7 +505,7 @@ class TestOther : public TestFixture { "{ { {\n" " long a = b / 0;\n" "} } }"); - ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15]: (error) Division by zero. [zerodiv]\n", errout_str()); } void zeroDiv6() { @@ -517,7 +518,7 @@ class TestOther : public TestFixture { "{ { {\n" " int a = b % 0;\n" "} } }"); - ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (error) Division by zero. [zerodiv]\n", errout_str()); } void zeroDiv7() { @@ -531,8 +532,8 @@ class TestOther : public TestFixture { " int a = x/2*3/0;\n" " int b = y/2*3%0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Division by zero.\n" - "[test.cpp:3]: (error) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (error) Division by zero. [zerodiv]\n" + "[test.cpp:3:16]: (error) Division by zero. [zerodiv]\n", errout_str()); } void zeroDiv8() { @@ -542,7 +543,7 @@ class TestOther : public TestFixture { " do_something(a);\n" " return 4 / a;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (error, inconclusive) Division by zero. [zerodiv]\n", errout_str()); } void zeroDiv9() { @@ -575,8 +576,8 @@ class TestOther : public TestFixture { " int res = (a+2)/0;\n" " int res = (a*2)/0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Division by zero.\n" - "[test.cpp:3]: (error) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (error) Division by zero. [zerodiv]\n" + "[test.cpp:3:18]: (error) Division by zero. [zerodiv]\n", errout_str()); check("void f() {\n" " int res = (a+2)/0;\n" " int res = (a*2)/0;\n" @@ -589,7 +590,7 @@ class TestOther : public TestFixture { check("intmax_t f() {\n" " return 1 / imaxabs(0);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (error) Division by zero. [zerodiv]\n", errout_str()); } void zeroDiv13() { // #7324 @@ -599,7 +600,7 @@ class TestOther : public TestFixture { " dividend = dividend / (--divisor);\n" " return dividend;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:25]: (error) Division by zero. [zerodiv]\n", errout_str()); } void zeroDiv14() { @@ -610,7 +611,7 @@ class TestOther : public TestFixture { " std::cout << ix / (i >> 1) << std::endl;\n" " std::cout << dx / (i >> 1) << std::endl;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (error) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:21]: (error) Division by zero. [zerodiv]\n", errout_str()); } void zeroDiv15() { // #8319 @@ -620,7 +621,7 @@ class TestOther : public TestFixture { " const int r = 1 / f(d);\n" " return r;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:21]: (error) Division by zero. [zerodiv]\n", errout_str()); } // #11158 @@ -664,7 +665,7 @@ class TestOther : public TestFixture { " return 1 / (x-y);\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3.\n", + "[test.cpp:2:11] -> [test.cpp:3:14]: (warning) Either the condition 'x==y' is redundant or there is division by zero at line 3. [zerodivcond]\n", errout_str()); } @@ -674,7 +675,7 @@ class TestOther : public TestFixture { " for (int i = 0;;)\n" " int j = 10 / i;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:20]: (error) Division by zero. [zerodiv]\n", errout_str()); } void zeroDiv20() @@ -684,7 +685,7 @@ class TestOther : public TestFixture { " uint16_t x = 0xFFFFU;\n" // UINT16_MAX=0xFFFF " return 42/(++x);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14]: (error) Division by zero. [zerodiv]\n", errout_str()); } void zeroDiv21() @@ -695,7 +696,7 @@ class TestOther : public TestFixture { "int g() {\n" " return f(1);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (error) Division by zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (error) Division by zero. [zerodiv]\n", errout_str()); } void zeroDivCond() { @@ -703,25 +704,25 @@ class TestOther : public TestFixture { " int y = 17 / x;\n" " if (x > 0) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\n", errout_str()); check("void f(unsigned int x) {\n" " int y = 17 / x;\n" " if (x >= 1) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\n", errout_str()); check("void f(int x) {\n" " int y = 17 / x;\n" " if (x == 0) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\n", errout_str()); check("void f(unsigned int x) {\n" " int y = 17 / x;\n" " if (x != 0) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\n", errout_str()); // function call check("void f1(int x, int y) { c=x/y; }\n" @@ -730,7 +731,7 @@ class TestOther : public TestFixture { " if (y>0){}\n" "}"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:1]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1.\n", + "[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\n", errout_str()); // avoid false positives when variable is changed after division @@ -761,7 +762,7 @@ class TestOther : public TestFixture { " do_something();\n" " if (x != 0) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:4]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\n", errout_str()); } check("void do_something(int value);\n" @@ -868,28 +869,28 @@ class TestOther : public TestFixture { " double x = 3.0 / 0.0 + 1.0;\n" " printf(\"%f\", x);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Using NaN/Inf in a computation.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\n", errout_str()); check("void f()\n" "{\n" " double x = 3.0 / 0.0 - 1.0;\n" " printf(\"%f\", x);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Using NaN/Inf in a computation.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\n", errout_str()); check("void f()\n" "{\n" " double x = 1.0 + 3.0 / 0.0;\n" " printf(\"%f\", x);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Using NaN/Inf in a computation.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\n", errout_str()); check("void f()\n" "{\n" " double x = 1.0 - 3.0 / 0.0;\n" " printf(\"%f\", x);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Using NaN/Inf in a computation.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\n", errout_str()); check("void f()\n" "{\n" @@ -970,7 +971,7 @@ class TestOther : public TestFixture { " for ( ; i < 10; ++i) ;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) The scope of the variable 'i' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\n", errout_str()); check("void f(int x) {\n" " const unsigned char i = 0;\n" @@ -988,7 +989,7 @@ class TestOther : public TestFixture { " for ( ; i < 10; ++i) ;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) The scope of the variable 'i' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\n", errout_str()); } void varScope6() { @@ -1067,7 +1068,7 @@ class TestOther : public TestFixture { " edgeResistance = (edge+1) / 2.0;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'edgeResistance' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\n", errout_str()); } void varScope9() { @@ -1126,7 +1127,7 @@ class TestOther : public TestFixture { " foo(i);\n" " foo(j);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'i' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\n", errout_str()); check("void f(int x) {\n" " int i[5];\n" @@ -1221,7 +1222,7 @@ class TestOther : public TestFixture { " foo(a);\n" " } while(z());\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'a' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\n", errout_str()); } void varScope17() { @@ -1232,7 +1233,7 @@ class TestOther : public TestFixture { " morestuff(x);\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'x' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\n", errout_str()); check("void f() {\n" " int x;\n" @@ -1242,7 +1243,7 @@ class TestOther : public TestFixture { " }\n" " if (b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'x' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\n", errout_str()); } void varScope18() { @@ -1262,7 +1263,7 @@ class TestOther : public TestFixture { " do_something(x);\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'x' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\n", errout_str()); check("void f() {\n" " short x;\n" @@ -1296,7 +1297,7 @@ class TestOther : public TestFixture { " break;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'x' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\n", errout_str()); check("void f() {\n" " short x;\n" @@ -1358,7 +1359,7 @@ class TestOther : public TestFixture { " ++i;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'p' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\n", errout_str()); } void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda @@ -1378,7 +1379,7 @@ class TestOther : public TestFixture { " r.dostuff();\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'r' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\n", errout_str()); check("void f(Foo x) {\n" " Foo foo = x;\n" @@ -1397,7 +1398,7 @@ class TestOther : public TestFixture { " if (currtime > t) {}\n" " }\n" "}", false); - ASSERT_EQUALS("[test.c:2]: (style) The scope of the variable 'currtime' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\n", errout_str()); } void varScope26() { @@ -1427,7 +1428,7 @@ class TestOther : public TestFixture { " int x = 0;\n" " if (id == ABC) { return x; }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) The scope of the variable 'x' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\n", errout_str()); } void varScope28() { @@ -1450,8 +1451,8 @@ class TestOther : public TestFixture { " g(e, s);\n" " }\n" "}\n", false); - ASSERT_EQUALS("[test.c:4]: (style) The scope of the variable 'e' can be reduced.\n" - "[test.c:5]: (style) The scope of the variable 's' can be reduced.\n", + ASSERT_EQUALS("[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\n" + "[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\n", errout_str()); check("void f(bool b) {\n" @@ -1461,7 +1462,7 @@ class TestOther : public TestFixture { " g(s);\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 's' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\n", errout_str()); check("auto foo(std::vector& vec, bool flag) {\n" " std::vector dummy;\n" @@ -1474,7 +1475,7 @@ class TestOther : public TestFixture { " }\n" " return *iter;\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'vec' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\n", errout_str()); check("auto& foo(std::vector& vec, bool flag) {\n" " std::vector dummy;\n" @@ -1586,11 +1587,11 @@ class TestOther : public TestFixture { " h(w);\n" " h(v);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:25]: (style) The scope of the variable 'w' can be reduced.\n" - "[test.cpp:32]: (style) The scope of the variable 'w' can be reduced.\n" - "[test.cpp:60]: (style) The scope of the variable 'w' can be reduced.\n" - "[test.cpp:67]: (style) The scope of the variable 'w' can be reduced.\n" - "[test.cpp:74]: (style) The scope of the variable 'w' can be reduced.\n", + ASSERT_EQUALS("[test.cpp:25:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\n" + "[test.cpp:32:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\n" + "[test.cpp:60:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\n" + "[test.cpp:67:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\n" + "[test.cpp:74:22]: (style) The scope of the variable 'w' can be reduced. [variableScope]\n", errout_str()); } @@ -1602,7 +1603,7 @@ class TestOther : public TestFixture { " for (auto x : v)\n" " w = g([&]() { x; }, w);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (warning) Unused variable value 'x'\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:23]: (warning) Unused variable value 'x' [constStatement]\n", errout_str()); } void varScope33() { // #11131 @@ -1647,11 +1648,11 @@ class TestOther : public TestFixture { " if (k == 5) {}\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:21]: (style) The scope of the variable 'str' can be reduced.\n" - "[test.cpp:22]: (style) The scope of the variable 'str2' can be reduced.\n" - "[test.cpp:23]: (style) The scope of the variable 'str3' can be reduced.\n" - "[test.cpp:31]: (style) The scope of the variable 'i' can be reduced.\n" - "[test.cpp:37]: (style) The scope of the variable 'k' can be reduced.\n", + ASSERT_EQUALS("[test.cpp:21:17]: (style) The scope of the variable 'str' can be reduced. [variableScope]\n" + "[test.cpp:22:17]: (style) The scope of the variable 'str2' can be reduced. [variableScope]\n" + "[test.cpp:23:17]: (style) The scope of the variable 'str3' can be reduced. [variableScope]\n" + "[test.cpp:31:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\n" + "[test.cpp:37:9]: (style) The scope of the variable 'k' can be reduced. [variableScope]\n", errout_str()); } @@ -1696,7 +1697,7 @@ class TestOther : public TestFixture { " g(buf, src);\n" " printf(\"%d: %s\\n\", err, msg);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) The scope of the variable 'buf' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\n", errout_str()); } void varScope36() { @@ -1709,7 +1710,7 @@ class TestOther : public TestFixture { " for( i = 0U; i < 5U; i++ ) {}\n" " }\n" "}\n", true, false); - ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'i' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\n", errout_str()); } void varScope37() { @@ -1724,7 +1725,7 @@ class TestOther : public TestFixture { " }\n" " }\n" "}\n", true, false); - ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'i' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\n", errout_str()); } void varScope38() { @@ -1770,9 +1771,9 @@ class TestOther : public TestFixture { " }\n" " return 0.0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) The scope of the variable 'a' can be reduced.\n" - "[test.cpp:4]: (style) The scope of the variable 'b' can be reduced.\n" - "[test.cpp:5]: (style) The scope of the variable 'c' can be reduced.\n", + ASSERT_EQUALS("[test.cpp:3:12]: (style) The scope of the variable 'a' can be reduced. [variableScope]\n" + "[test.cpp:4:12]: (style) The scope of the variable 'b' can be reduced. [variableScope]\n" + "[test.cpp:5:12]: (style) The scope of the variable 'c' can be reduced. [variableScope]\n", errout_str()); check("struct S { int a; };\n" // #12618 @@ -1784,8 +1785,8 @@ class TestOther : public TestFixture { " return x + y;\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) The scope of the variable 'x' can be reduced.\n" - "[test.cpp:5]: (style) The scope of the variable 'y' can be reduced.\n", + ASSERT_EQUALS("[test.cpp:3:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\n" + "[test.cpp:5:9]: (style) The scope of the variable 'y' can be reduced. [variableScope]\n", errout_str()); } @@ -1810,7 +1811,7 @@ class TestOther : public TestFixture { " get_errmsg(buf, sizeof(buf), err);\n" " printf(\"%d: %s\\n\", err, msg);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (style) The scope of the variable 'buf' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\n", errout_str()); } void varScope42() { @@ -1842,7 +1843,7 @@ class TestOther : public TestFixture { " f(msg, buf);\n" " printf(\"result: %s\\n\", msg);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) The scope of the variable 'buf' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\n", errout_str()); check("void f(int **, char *);\n" "void g(int e) {\n" @@ -1852,7 +1853,7 @@ class TestOther : public TestFixture { " f(&msg, buf);\n" " printf(\"result: %d\\n\", *msg);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) The scope of the variable 'buf' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (style) The scope of the variable 'buf' can be reduced. [variableScope]\n", errout_str()); check("void f(const char *&, const char *&);\n" "void g(int e) {\n" @@ -1870,7 +1871,7 @@ class TestOther : public TestFixture { " if (b)\n" " g(\"%d %s\", 1, s);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) The scope of the variable 's' can be reduced.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\n", errout_str()); } #define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__) @@ -1893,70 +1894,70 @@ class TestOther : public TestFixture { "{\n" " Base * b = (Base *) derived;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); checkOldStylePointerCast("class Base;\n" "void foo()\n" "{\n" " Base * b = (const Base *) derived;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:17]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); checkOldStylePointerCast("class Base;\n" "void foo()\n" "{\n" " Base * b = (const Base * const) derived;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:23]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); checkOldStylePointerCast("class Base;\n" "void foo()\n" "{\n" " Base * b = (volatile Base *) derived;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:17]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); checkOldStylePointerCast("class Base;\n" "void foo()\n" "{\n" " Base * b = (volatile Base * const) derived;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:26]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); checkOldStylePointerCast("class Base;\n" "void foo()\n" "{\n" " Base * b = (const volatile Base *) derived;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:23]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); checkOldStylePointerCast("class Base;\n" "void foo()\n" "{\n" " Base * b = (const volatile Base * const) derived;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:32]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); checkOldStylePointerCast("class Base;\n" "void foo()\n" "{\n" " Base * b = (const Base *) ( new Derived() );\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:17]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); checkOldStylePointerCast("class Base;\n" "void foo()\n" "{\n" " Base * b = (const Base *) new Derived();\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:17]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); checkOldStylePointerCast("class Base;\n" "void foo()\n" "{\n" " Base * b = (const Base *) new short[10];\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:17]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); checkOldStylePointerCast("class B;\n" "class A\n" @@ -1977,13 +1978,13 @@ class TestOther : public TestFixture { "class X : public Base {\n" " X() : Base((SomeType*)7) {}\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style) C-style pointer casting\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); checkOldStylePointerCast("class SomeType;\n" "class X : public Base {\n" " X() : Base((SomeType*)var) {}\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (style) C-style pointer casting\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); checkOldStylePointerCast("class SomeType;\n" "class X : public Base {\n" @@ -2008,7 +2009,7 @@ class TestOther : public TestFixture { " std::vector v;\n" " v.push_back((Base*)new Derived);\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (style) C-style pointer casting\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); // #7709 checkOldStylePointerCast("typedef struct S S;\n" @@ -2031,16 +2032,16 @@ class TestOther : public TestFixture { " TT* tt = (TT*)i;\n" " TT2* tt2 = (TT2*)i;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:10]: (style) C-style pointer casting\n" - "[test.cpp:11]: (style) C-style pointer casting\n" - "[test.cpp:12]: (style) C-style pointer casting\n" - "[test.cpp:13]: (style) C-style pointer casting\n" - "[test.cpp:14]: (style) C-style pointer casting\n" - "[test.cpp:15]: (style) C-style pointer casting\n" - "[test.cpp:16]: (style) C-style pointer casting\n" - "[test.cpp:17]: (style) C-style pointer casting\n" - "[test.cpp:18]: (style) C-style pointer casting\n" - "[test.cpp:19]: (style) C-style pointer casting\n", + ASSERT_EQUALS("[test.cpp:10:13]: (style) C-style pointer casting [cstyleCast]\n" + "[test.cpp:11:15]: (style) C-style pointer casting [cstyleCast]\n" + "[test.cpp:12:22]: (style) C-style pointer casting [cstyleCast]\n" + "[test.cpp:13:13]: (style) C-style pointer casting [cstyleCast]\n" + "[test.cpp:14:21]: (style) C-style pointer casting [cstyleCast]\n" + "[test.cpp:15:15]: (style) C-style pointer casting [cstyleCast]\n" + "[test.cpp:16:16]: (style) C-style pointer casting [cstyleCast]\n" + "[test.cpp:17:16]: (style) C-style pointer casting [cstyleCast]\n" + "[test.cpp:18:15]: (style) C-style pointer casting [cstyleCast]\n" + "[test.cpp:19:17]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); // #8649 @@ -2050,8 +2051,8 @@ class TestOther : public TestFixture { " g((S*&)i);\n" " S*& r = (S*&)i;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n" - "[test.cpp:5]: (style) C-style pointer casting\n", + ASSERT_EQUALS("[test.cpp:4:7]: (style) C-style pointer casting [cstyleCast]\n" + "[test.cpp:5:13]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); // #10823 @@ -2065,8 +2066,8 @@ class TestOther : public TestFixture { " T** p1 = (T**)v1;\n" " T*** p2 = (T***)v2;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) C-style pointer casting\n" - "[test.cpp:3]: (style) C-style pointer casting\n", + ASSERT_EQUALS("[test.cpp:2:14]: (style) C-style pointer casting [cstyleCast]\n" + "[test.cpp:3:15]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); // #12446 @@ -2080,9 +2081,9 @@ class TestOther : public TestFixture { " auto pu = (union U*)p;\n" " auto pv = (std::vector*)(p);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (style) C-style pointer casting\n" - "[test.cpp:8]: (style) C-style pointer casting\n" - "[test.cpp:9]: (style) C-style pointer casting\n", + ASSERT_EQUALS("[test.cpp:7:15]: (style) C-style pointer casting [cstyleCast]\n" + "[test.cpp:8:16]: (style) C-style pointer casting [cstyleCast]\n" + "[test.cpp:9:15]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); // #12447 @@ -2090,7 +2091,7 @@ class TestOther : public TestFixture { " int& r = (int&)i;\n" " r = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) C-style reference casting\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (style) C-style reference casting [cstyleCast]\n", errout_str()); // #11430 checkOldStylePointerCast("struct B {\n" @@ -2103,7 +2104,7 @@ class TestOther : public TestFixture { " using float_ptr = float*;\n" " return N::f(float_ptr(b.data()));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:9]: (style) C-style pointer casting\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:17]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); } #define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__) @@ -2127,34 +2128,34 @@ class TestOther : public TestFixture { " delete [] (double*)f;\n" " delete [] (long double const*)(new float[10]);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (portability) Casting between float * and double * which have an incompatible binary data representation.\n" - "[test.cpp:4]: (portability) Casting between float * and const long double * which have an incompatible binary data representation.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\n" + "[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\n", errout_str()); checkInvalidPointerCast("void test(const float* f) {\n" " double *d = (double*)f;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (portability) Casting between const float * and double * which have an incompatible binary data representation.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\n", errout_str()); checkInvalidPointerCast("void test(double* d1) {\n" " long double *ld = (long double*)d1;\n" " double *d2 = (double*)ld;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (portability) Casting between double * and long double * which have an incompatible binary data representation.\n" - "[test.cpp:3]: (portability) Casting between long double * and double * which have an incompatible binary data representation.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\n" + "[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\n", errout_str()); checkInvalidPointerCast("char* test(int* i) {\n" " long double *d = (long double*)(i);\n" " double *d = (double*)(i);\n" " float *f = reinterpret_cast(i);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation.\n" - "[test.cpp:3]: (portability) Casting between signed int * and double * which have an incompatible binary data representation.\n" - "[test.cpp:4]: (portability) Casting between signed int * and float * which have an incompatible binary data representation.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\n" + "[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\n" + "[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\n", errout_str()); checkInvalidPointerCast("float* test(unsigned int* i) {\n" " return (float*)i;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\n", errout_str()); checkInvalidPointerCast("float* test(unsigned int* i) {\n" " return (float*)i[0];\n" @@ -2164,7 +2165,7 @@ class TestOther : public TestFixture { checkInvalidPointerCast("float* test(double& d) {\n" " return (float*)&d;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (portability) Casting between double * and float * which have an incompatible binary data representation.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\n", errout_str()); checkInvalidPointerCast("void test(float* data) {\n" " f.write((char*)data,sizeof(float));\n" @@ -2174,7 +2175,7 @@ class TestOther : public TestFixture { checkInvalidPointerCast("void test(float* data) {\n" " f.write((char*)data,sizeof(float));\n" "}", true, true); // #3639 - ASSERT_EQUALS("[test.cpp:2]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\n", errout_str()); checkInvalidPointerCast("long long* test(float* f) {\n" @@ -2186,7 +2187,7 @@ class TestOther : public TestFixture { " foo((long long*)f);\n" " return reinterpret_cast(c);\n" "}", true); - ASSERT_EQUALS("[test.cpp:2]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\n", errout_str()); checkInvalidPointerCast("Q_DECLARE_METATYPE(int*)"); // #4135 - don't crash } @@ -2194,7 +2195,7 @@ class TestOther : public TestFixture { void passedByValue() { check("void f(const std::string str) {}"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'str' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("void f(std::unique_ptr ptr) {}"); ASSERT_EQUALS("", errout_str()); @@ -2217,16 +2218,16 @@ class TestOther : public TestFixture { ASSERT_EQUALS("", errout_str()); check("class Foo;\nvoid f(const Foo foo) {}"); // Unknown class - ASSERT_EQUALS("[test.cpp:2]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\n", errout_str()); check("class Foo { std::vector v; };\nvoid f(const Foo foo) {}"); // Large class (STL member) - ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 'foo' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\n", errout_str()); check("class Foo { int i; };\nvoid f(const Foo foo) {}"); // Small class ASSERT_EQUALS("", errout_str()); check("class Foo { int i[6]; };\nvoid f(const Foo foo) {}"); // Large class (array) - ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 'foo' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\n", errout_str()); check("class Foo { std::string* s; };\nvoid f(const Foo foo) {}"); // Small class (pointer) ASSERT_EQUALS("", errout_str()); @@ -2235,10 +2236,10 @@ class TestOther : public TestFixture { ASSERT_EQUALS("", errout_str()); check("class X { std::string s; }; class Foo : X { };\nvoid f(const Foo foo) {}"); // Large class (inherited) - ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 'foo' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\n", errout_str()); check("class X { std::string s; }; class Foo { X x; };\nvoid f(const Foo foo) {}"); // Large class (inherited) - ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 'foo' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\n", errout_str()); check("void f(const std::string &str) {}"); ASSERT_EQUALS("", errout_str()); @@ -2254,10 +2255,10 @@ class TestOther : public TestFixture { ASSERT_EQUALS("", errout_str()); check("void f(const std::vector v) {}"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str()); check("void f(const std::vector v) {}"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str()); check("void f(const std::vector::size_type s) {}"); ASSERT_EQUALS("", errout_str()); @@ -2269,16 +2270,16 @@ class TestOther : public TestFixture { ASSERT_EQUALS("", errout_str()); check("void f(const std::map v) {}"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str()); check("void f(const std::map v) {}"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str()); check("void f(const std::map v) {}"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str()); check("void f(const std::map v) {}"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str()); check("void f(const std::streamoff pos) {}"); ASSERT_EQUALS("", errout_str()); @@ -2302,7 +2303,7 @@ class TestOther : public TestFixture { check("class X {\n" " virtual void func(const std::string str) {}\n" "};"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 'str' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("enum X;\n" "void foo(X x1){}\n"); @@ -2332,7 +2333,7 @@ class TestOther : public TestFixture { check("struct S { char A[8][8]; };\n" "void f(S s) {}\n"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 's' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\n", errout_str()); check("union U {\n" // don't crash " int a;\n" @@ -2375,9 +2376,9 @@ class TestOther : public TestFixture { " for (int i = 0; i < v.size(); ++i)\n" " v[i][0] = x(i);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 'v' should be passed by const reference.\n" - "[test.cpp:10]: (performance) Function parameter 'v' should be passed by const reference.\n" - "[test.cpp:18]: (performance) Function parameter 'v' should be passed by const reference.\n", + ASSERT_EQUALS("[test.cpp:2:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n" + "[test.cpp:10:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n" + "[test.cpp:18:38]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str()); check("struct S {\n" // #11995 @@ -2398,12 +2399,12 @@ class TestOther : public TestFixture { "void f(std::vector v) {\n" " N::g(v[0]);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (performance) Function parameter 'v' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:25]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str()); check("void f(const std::string& s, std::string t) {\n" // #12083 " const std::string& v = !s.empty() ? s : t;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 't' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\n", errout_str()); /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build(); check("struct S {\n" // #12138 @@ -2433,15 +2434,15 @@ class TestOther : public TestFixture { "bool f(C c) {\n" " return c.l.empty();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (performance) Function parameter 's' should be passed by const reference.\n" - "[test.cpp:6]: (performance) Function parameter 'c' should be passed by const reference.\n", + ASSERT_EQUALS("[test.cpp:3:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\n" + "[test.cpp:6:10]: (performance) Function parameter 'c' should be passed by const reference. [passedByValue]\n", errout_str()); check("struct S { std::list a[1][1]; };\n" "bool f(S s) {\n" " return s.a[0][0].empty();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 's' should be passed by const reference.\n", + ASSERT_EQUALS("[test.cpp:2:10]: (performance) Function parameter 's' should be passed by const reference. [passedByValue]\n", errout_str()); check("struct S {\n" @@ -2457,7 +2458,7 @@ class TestOther : public TestFixture { "void g(const std::vector v[2]);\n" "void g(const std::vector v[2]) {}\n" "int h(const std::array, 2> a) { return a[0][0]; }\n"); - ASSERT_EQUALS("[test.cpp:4]: (performance) Function parameter 'a' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:45]: (performance) Function parameter 'a' should be passed by const reference. [passedByValue]\n", errout_str()); check("void f(const std::array a[]) {}\n"); // #13524 ASSERT_EQUALS("", errout_str()); @@ -2471,17 +2472,17 @@ class TestOther : public TestFixture { void passedByValue_nonConst() { check("void f(std::string str) {}"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'str' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("void f(std::string str) {\n" " return str + x;\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'str' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("void f(std::string str) {\n" " std::cout << str;\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'str' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("void f(std::string str) {\n" " std::cin >> str;\n" @@ -2491,19 +2492,19 @@ class TestOther : public TestFixture { check("void f(std::string str) {\n" " std::string s2 = str;\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'str' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("void f(std::string str) {\n" " std::string& s2 = str;\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'str' should be passed by const reference.\n" - "[test.cpp:2]: (style) Variable 's2' can be declared as reference to const\n", + ASSERT_EQUALS("[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n" + "[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\n", errout_str()); check("void f(std::string str) {\n" " const std::string& s2 = str;\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'str' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("void f(std::string str) {\n" " str = \"\";\n" @@ -2519,13 +2520,13 @@ class TestOther : public TestFixture { "void f(std::string str) {\n" " foo(str);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 'str' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("void foo(std::string str);\n" "void f(std::string str) {\n" " foo(str);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 'str' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("void foo(std::string& str);\n" "void f(std::string str) {\n" @@ -2543,7 +2544,7 @@ class TestOther : public TestFixture { "void f(std::string str) {\n" " foo((a+b)*c, str, x);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 'str' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("std::string f(std::string str) {\n" " str += x;\n" @@ -2558,7 +2559,7 @@ class TestOther : public TestFixture { "Y f(X x) {\n" " x.func();\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (performance) Function parameter 'x' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\n", errout_str()); check("class X {\n" " void func();\n" @@ -2571,7 +2572,7 @@ class TestOther : public TestFixture { check("class X {\n" " void func(std::string str) {}\n" "};"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 'str' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("class X {\n" " virtual void func(std::string str) {}\n" // Do not warn about virtual functions, if 'str' is not declared as const @@ -2586,7 +2587,7 @@ class TestOther : public TestFixture { "};\n" "void f(Y y) {\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (performance) Function parameter 'y' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\n", errout_str()); check("class X {\n" " void* a;\n" @@ -2599,7 +2600,7 @@ class TestOther : public TestFixture { "};\n" "void f(X x, Y y) {\n" "}"); - ASSERT_EQUALS("[test.cpp:10]: (performance) Function parameter 'y' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\n", errout_str()); { // 8-byte data should be passed by const reference on 32-bit platform but not on 64-bit platform @@ -2611,7 +2612,7 @@ class TestOther : public TestFixture { /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build(); check(code, &s32); - ASSERT_EQUALS("[test.cpp:5]: (performance) Function parameter 'x' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\n", errout_str()); /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build(); check(code, &s64); @@ -2628,7 +2629,7 @@ class TestOther : public TestFixture { void passedByValue_externC() { check("struct X { int a[5]; }; void f(X v) { }"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str()); check("extern \"C\" { struct X { int a[5]; }; void f(X v) { } }"); ASSERT_EQUALS("", errout_str()); @@ -2637,7 +2638,7 @@ class TestOther : public TestFixture { ASSERT_EQUALS("", errout_str()); check("struct X { int a[5]; }; void f(const X v);"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str()); check("extern \"C\" { struct X { int a[5]; }; void f(const X v); }"); ASSERT_EQUALS("", errout_str()); @@ -2651,26 +2652,26 @@ class TestOther : public TestFixture { " int& i = x[0];\n" " return i;\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'x' should be passed by const reference.\n" - "[test.cpp:2]: (style) Variable 'i' can be declared as reference to const\n", + ASSERT_EQUALS("[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\n" + "[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\n", errout_str()); check("int f(std::vector& x) {\n" " return x[0];\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'x' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("int f(std::vector x) {\n" " const int& i = x[0];\n" " return i;\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'x' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\n", errout_str()); check("int f(std::vector x) {\n" " static int& i = x[0];\n" " return i;\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'x' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\n", errout_str()); check("int f(std::vector x) {\n" " int& i = x[0];\n" @@ -2699,7 +2700,7 @@ class TestOther : public TestFixture { check("const int& f(std::vector& x) {\n" " return x[0];\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'x' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("int f(std::vector& x) {\n" " x[0]++;\n" @@ -2778,7 +2779,7 @@ class TestOther : public TestFixture { check("void f(int& x, int& y) {\n" " y++;\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'x' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct A {\n" " explicit A(int& y) : x(&y) {}\n" @@ -2815,12 +2816,12 @@ class TestOther : public TestFixture { " for(auto x:v)\n" " x = 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'v' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\n", errout_str()); check("void f(std::vector& v) {\n" " for(auto& x:v) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'x' can be declared as reference to const\n", + ASSERT_EQUALS("[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\n", errout_str()); check("void f(std::vector& v) {\n" // #10980 @@ -2834,14 +2835,14 @@ class TestOther : public TestFixture { " if (i == 0) {}\n" " v.clear();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'i' can be declared as reference to const\n" - "[test.cpp:6]: (style) Variable 'i' can be declared as reference to const\n", + ASSERT_EQUALS("[test.cpp:2:15]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\n" + "[test.cpp:6:16]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\n", errout_str()); check("void f(std::vector& v) {\n" " for(const auto& x:v) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'v' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\n", errout_str()); check("void f(int& i) {\n" " int& j = i;\n" @@ -2945,14 +2946,14 @@ class TestOther : public TestFixture { " a x;\n" " x(i);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Parameter 'i' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\n", errout_str()); //cast or assignment to a non-const reference should prevent the warning check("struct T { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" @@ -2966,7 +2967,7 @@ class TestOther : public TestFixture { " x.dostuff();\n" " const U& y = x\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" @@ -2987,7 +2988,7 @@ class TestOther : public TestFixture { " const U& y = static_cast(x);\n" " y.mutate();\n" // to avoid warnings that y can be const "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" @@ -3000,19 +3001,19 @@ class TestOther : public TestFixture { " x.dostuff();\n" " const U& y = dynamic_cast(x)\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " const U& y = dynamic_cast(x);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " const U& y = dynamic_cast(x);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" @@ -3025,7 +3026,7 @@ class TestOther : public TestFixture { " x.dostuff();\n" " const U& y = dynamic_cast(x);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" @@ -3089,8 +3090,8 @@ class TestOther : public TestFixture { " x.dostuff();\n" " const U& y = (const U&)(x);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) C-style reference casting\n" - "[test.cpp:2]: (style) Parameter 'x' can be declared as reference to const\n", + ASSERT_EQUALS("[test.cpp:4:19]: (style) C-style reference casting [cstyleCast]\n" + "[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" @@ -3098,14 +3099,14 @@ class TestOther : public TestFixture { " U& y = (U&)(x);\n" " y.mutate();\n" // to avoid warnings that y can be const "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) C-style reference casting\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (style) C-style reference casting [cstyleCast]\n", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " const U& y = (typename const U&)(x);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) C-style reference casting\n" - "[test.cpp:2]: (style) Parameter 'x' can be declared as reference to const\n", + ASSERT_EQUALS("[test.cpp:4:0]: (style) C-style reference casting [cstyleCast]\n" + "[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" @@ -3113,14 +3114,14 @@ class TestOther : public TestFixture { " U& y = (typename U&)(x);\n" " y.mutate();\n" // to avoid warnings that y can be const "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) C-style reference casting\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (style) C-style reference casting [cstyleCast]\n", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " U* y = (U*)(&x);\n" " y->mutate();\n" // to avoid warnings that y can be const "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); check("struct C { void f() const; };\n" // #9875 - crash "\n" @@ -3128,7 +3129,7 @@ class TestOther : public TestFixture { " x.f();\n" " foo( static_cast(0) );\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Parameter 'x' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("class a {\n" " void foo(const int& i) const;\n" @@ -3145,7 +3146,7 @@ class TestOther : public TestFixture { "void f(int& i) {\n" " a()(i);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Parameter 'i' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (style) Parameter 'i' can be declared as reference to const [constParameterReference]\n", errout_str()); // #9767 check("void fct1(MyClass& object) {\n" @@ -3332,9 +3333,9 @@ class TestOther : public TestFixture { "void ah();\n" "void an();\n" "void h();"); - ASSERT_EQUALS("[test.cpp:131]: (style) Variable 'tm' can be declared as pointer to const\n" - "[test.cpp:136]: (style) Variable 'af' can be declared as pointer to const\n" - "[test.cpp:137]: (style) Variable 'ag' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\n" + "[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\n" + "[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\n", errout_str()); check("class C\n" @@ -3542,7 +3543,7 @@ class TestOther : public TestFixture { " d->f();\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:4]: (style) Variable 'd' can be declared as pointer to const\n", + "[test.cpp:4:8]: (style) Variable 'd' can be declared as pointer to const [constVariablePointer]\n", errout_str()); check("void g(const int*);\n" @@ -3551,7 +3552,7 @@ class TestOther : public TestFixture { " g(i);\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3]: (style) Variable 'i' can be declared as pointer to const\n", + "[test.cpp:3:15]: (style) Variable 'i' can be declared as pointer to const [constVariablePointer]\n", errout_str()); check("struct A {\n" // #11225 @@ -3565,9 +3566,9 @@ class TestOther : public TestFixture { "void g(A* a) {\n" " const B* b = (const B*)a;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:10]: (style) C-style pointer casting\n" - "[test.cpp:6]: (style) Parameter 'a' can be declared as pointer to const\n" - "[test.cpp:9]: (style) Parameter 'a' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:10:19]: (style) C-style pointer casting [cstyleCast]\n" + "[test.cpp:6:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:9:11]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void g(int*);\n" @@ -3580,7 +3581,7 @@ class TestOther : public TestFixture { "void f(std::vector& v) {\n" " g(v.data());\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'v' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct a {\n" " template \n" @@ -3622,15 +3623,15 @@ class TestOther : public TestFixture { check("bool f(std::string& s1, std::string& s2) {\n" // #12203 " return &s1 == &s2;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 's1' can be declared as reference to const\n" - "[test.cpp:1]: (style) Parameter 's2' can be declared as reference to const\n", + ASSERT_EQUALS("[test.cpp:1:21]: (style) Parameter 's1' can be declared as reference to const [constParameterReference]\n" + "[test.cpp:1:38]: (style) Parameter 's2' can be declared as reference to const [constParameterReference]\n", errout_str()); check("void f(int& r) {\n" // #12214 " (void)(true);\n" " if (r) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'r' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:13]: (style) Parameter 'r' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct S { void f(int&); };\n" // #12216 "void g(S& s, int& r, void (S::* p2m)(int&)) {\n" @@ -3658,7 +3659,7 @@ class TestOther : public TestFixture { "void f(T& t) {\n" " std::list c(1, E::F(&t));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:9]: (style) Parameter 't' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct T;\n" "struct U {\n" @@ -3668,7 +3669,7 @@ class TestOther : public TestFixture { "void f(T& t) {\n" " g(U::V(&t));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (style) Parameter 't' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:11]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\n", errout_str()); check("void f1(std::vector& v) {\n" // #11207 " auto it = v.cbegin();\n" @@ -3684,8 +3685,8 @@ class TestOther : public TestFixture { " ++it;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'v' can be declared as reference to const\n" - "[test.cpp:8]: (style) Parameter 'v' can be declared as reference to const\n", + ASSERT_EQUALS("[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\n" + "[test.cpp:8:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\n", errout_str()); check("void cb(const std::string&);\n" // #12349, #12350, #12351 @@ -3713,12 +3714,12 @@ class TestOther : public TestFixture { " const std::string& str(*s);\n" " cb(str);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 's' can be declared as reference to const\n" - "[test.cpp:6]: (style) Parameter 's' can be declared as reference to const\n" - "[test.cpp:18]: (style) Parameter 's' can be declared as reference to const\n" - "[test.cpp:10]: (style) Parameter 's' can be declared as pointer to const\n" - "[test.cpp:14]: (style) Parameter 's' can be declared as pointer to const\n" - "[test.cpp:22]: (style) Parameter 's' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:2:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\n" + "[test.cpp:6:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\n" + "[test.cpp:18:21]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\n" + "[test.cpp:10:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:14:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:22:21]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("struct S {\n" @@ -3740,14 +3741,14 @@ class TestOther : public TestFixture { check("int f(int& t) {\n" // #11713 " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 't' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:12]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\n", errout_str()); check("void f(std::list& v) {\n" // #12202 " v.remove_if([](std::string& s) {\n" " return true;\n" " });\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 's' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:33]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct S {\n" // #12762 " std::vector m;\n" @@ -3757,7 +3758,7 @@ class TestOther : public TestFixture { " std::vector& r = m;\n" " g(r[0] * 2);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (style) Variable 'r' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:23]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\n", errout_str()); check("std::iostream& get();\n" // #12940 "std::iostream& Fun() {\n" @@ -3788,16 +3789,16 @@ class TestOther : public TestFixture { "int f(std::vector& v) {\n" " return *v.cbegin();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Parameter 's' can be declared as reference to const\n" - "[test.cpp:7]: (style) Parameter 't' can be declared as reference to const\n" - "[test.cpp:10]: (style) Parameter 'v' can be declared as reference to const\n", + ASSERT_EQUALS("[test.cpp:3:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\n" + "[test.cpp:7:10]: (style) Parameter 't' can be declared as reference to const [constParameterReference]\n" + "[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\n", errout_str()); } void constParameterCallback() { check("int callback(std::vector& x) { return x[0]; }\n" "void f() { dostuff(callback); }"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:1]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\n", errout_str()); // #9906 check("class EventEngine : public IEventEngine {\n" @@ -3815,59 +3816,59 @@ class TestOther : public TestFixture { "void EventEngine::signalEvent(ev::sig& signal, int revents) {\n" " switch (signal.signum) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:10] -> [test.cpp:13]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s).\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\n", errout_str()); check("void f(int* p) {}\n" // 12843 "void g(std::map&m) {\n" " m[&f] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const. " - "However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s).\n", + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. " + "However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\n", errout_str()); } void constPointer() { check("void foo(int *p) { return *p; }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(int *p) { x = *p; }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(int *p) { int &ref = *p; ref = 12; }"); ASSERT_EQUALS("", errout_str()); check("void foo(int *p) { x = *p + 10; }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(int *p) { return p[10]; }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(int *p) { int &ref = p[0]; ref = 12; }"); ASSERT_EQUALS("", errout_str()); check("void foo(int *p) { x[*p] = 12; }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(int *p) { if (p) {} }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(int *p) { if (p || x) {} }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(int *p) { if (p == 0) {} }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(int *p) { if (!p) {} }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(int *p) { if (*p > 123) {} }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(int *p) { return *p + 1; }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(int *p) { return *p > 1; }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(const int* c) { if (c == 0) {}; }"); ASSERT_EQUALS("", errout_str()); @@ -3979,7 +3980,7 @@ class TestOther : public TestFixture { " if (h) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:5]: (style) Variable 'h' can be declared as pointer to const\n", + "[test.cpp:5:22]: (style) Variable 'h' can be declared as pointer to const [constVariableReference]\n", errout_str()); check("void f(const std::vector& v) {\n" @@ -3989,7 +3990,7 @@ class TestOther : public TestFixture { " if (p == nullptr) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:2]: (style) Variable 'p' can be declared as pointer to const\n", + "[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\n", errout_str()); check("void f(std::vector& v) {\n" @@ -4002,8 +4003,8 @@ class TestOther : public TestFixture { " for (const int* p : v)\n" " if (p == nullptr) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'v' can be declared as reference to const\n" - "[test.cpp:2]: (style) Variable 'p' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:1:27]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\n" + "[test.cpp:2:22]: (style) Variable 'p' can be declared as pointer to const [constVariableReference]\n", errout_str()); check("void f(std::vector& v) {\n" @@ -4012,7 +4013,7 @@ class TestOther : public TestFixture { " for (const auto* p : v)\n" " if (p == nullptr) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'v' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:33]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\n", errout_str()); check("void f(const std::vector& v) {\n" " for (const auto& p : v)\n" @@ -4057,13 +4058,13 @@ class TestOther : public TestFixture { "void f(A* x) {\n" " if (x == nullptr) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("using A = int;\n" "void f(A* x) {\n" " if (x == nullptr) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("struct S { void v(); };\n" // #11095 "void f(S* s) {\n" @@ -4080,8 +4081,8 @@ class TestOther : public TestFixture { " }\n" " v.clear();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'p' can be declared as pointer to const\n" - "[test.cpp:5]: (style) Variable 'p' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:2:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\n" + "[test.cpp:5:16]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\n", errout_str()); check("void f() {\n" @@ -4095,8 +4096,8 @@ class TestOther : public TestFixture { check("ptrdiff_t f(int *p0, int *p1) {\n" // #11148 " return p0 - p1;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p0' can be declared as pointer to const\n" - "[test.cpp:1]: (style) Parameter 'p1' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:1:18]: (style) Parameter 'p0' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:1:27]: (style) Parameter 'p1' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void f() {\n" @@ -4131,11 +4132,11 @@ class TestOther : public TestFixture { "void f6(S& s) {\n" " j(1, 2, &s);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:20]: (style) Parameter 's' can be declared as reference to const\n" - "[test.cpp:23]: (style) Parameter 's' can be declared as reference to const\n" - "[test.cpp:8]: (style) Parameter 's' can be declared as pointer to const\n" - "[test.cpp:11]: (style) Parameter 's' can be declared as pointer to const\n" - "[test.cpp:14]: (style) Parameter 's' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:20:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\n" + "[test.cpp:23:12]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\n" + "[test.cpp:8:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:11:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:14:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void g(int, const int*);\n" @@ -4144,7 +4145,7 @@ class TestOther : public TestFixture { " g(1, p);\n" " h(p);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Parameter 'p' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void f(int, const int*);\n" @@ -4162,7 +4163,7 @@ class TestOther : public TestFixture { " continue;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (style) Variable 's' can be declared as reference to const\n", errout_str()); // don't crash + ASSERT_EQUALS("[test.cpp:5:12]: (style) Variable 's' can be declared as reference to const [constVariableReference]\n", errout_str()); // don't crash check("void f(int& i) {\n" " new (&i) int();\n" @@ -4173,14 +4174,14 @@ class TestOther : public TestFixture { " int& r = i;\n" " if (!&r) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'r' can be declared as reference to const\n", errout_str()); // don't crash + ASSERT_EQUALS("[test.cpp:2:10]: (style) Variable 'r' can be declared as reference to const [constVariableReference]\n", errout_str()); // don't crash check("class C;\n" // #11646 "void g(const C* const p);\n" "void f(C* c) {\n" " g(c);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Parameter 'c' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Parameter 'c' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("typedef void (*cb_t)(int*);\n" // #11674 "void cb(int* p) {\n" @@ -4190,8 +4191,8 @@ class TestOther : public TestFixture { "void f() {\n" " g(cb);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:2]: (style) Parameter 'p' can be declared as pointer to const. " - "However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s).\n", + ASSERT_EQUALS("[test.cpp:7:7] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. " + "However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\n", errout_str()); check("typedef void (*cb_t)(int*);\n" @@ -4202,8 +4203,8 @@ class TestOther : public TestFixture { "void f() {\n" " g(::cb);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:2]: (style) Parameter 'p' can be declared as pointer to const. " - "However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s).\n", + ASSERT_EQUALS("[test.cpp:7:9] -> [test.cpp:2:14]: (style) Parameter 'p' can be declared as pointer to const. " + "However it seems that 'cb' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\n", errout_str()); check("void f1(std::vector* p) {\n" // #11681 @@ -4233,9 +4234,9 @@ class TestOther : public TestFixture { "void g3(S* s) {\n" " k(s->i);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const\n" - "[test.cpp:13]: (style) Parameter 's' can be declared as pointer to const\n" - "[test.cpp:19]: (style) Parameter 's' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:1:27]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:13:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:19:12]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("struct S {\n" // #11573 @@ -4249,7 +4250,7 @@ class TestOther : public TestFixture { " for (const auto* p : t->v)\n" " if (strcmp(p->g(), n) == 0) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (style) Parameter 't' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:8:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void f(int*& p, int* q) {\n" @@ -4261,18 +4262,18 @@ class TestOther : public TestFixture { "void f(S* s) {\n" " if (s->a[0]) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 's' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("size_t f(char* p) {\n" // #11842 " return strlen(p);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void f(int* p) {\n" // #11862 " long long j = *(p++);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\n" @@ -4283,22 +4284,22 @@ class TestOther : public TestFixture { check("void g(bool *r, std::size_t *b) {\n" // #12129 " if (*r && *b >= 5) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'r' can be declared as pointer to const\n" - "[test.cpp:1]: (style) Parameter 'b' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:1:14]: (style) Parameter 'r' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:1:30]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void f(int i) {\n" // #12185 " void* p = &i;\n" " std::cout << p << '\\n';\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'p' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:2:11]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\n", errout_str()); check("struct S { const T* t; };\n" // #12206 "void f(S* s) {\n" " if (s->t.i) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 's' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void f(char *a1, char *a2) {\n" // #12252 @@ -4306,14 +4307,14 @@ class TestOther : public TestFixture { " sprintf(b, \"%s_%s\", a1, a2);\n" " delete[] b;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'a1' can be declared as pointer to const\n" - "[test.cpp:1]: (style) Parameter 'a2' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:1:14]: (style) Parameter 'a1' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:1:24]: (style) Parameter 'a2' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("int f(int* p) {\n" // #11713 " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void f(int *src, int* dst) {\n" // #12518 @@ -4324,35 +4325,35 @@ class TestOther : public TestFixture { "void g(int* dst) {\n" " (int&)*dst = 5;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'src' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:1:13]: (style) Parameter 'src' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("struct S {};\n" "void f(T* t) {\n" " S* s = (S*)t->p;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) C-style pointer casting\n" - "[test.cpp:3]: (style) Variable 's' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:3:12]: (style) C-style pointer casting [cstyleCast]\n" + "[test.cpp:3:8]: (style) Variable 's' can be declared as pointer to const [constVariablePointer]\n", errout_str()); // don't crash check("struct S { int i; };\n" // #12205 "void f(S* s) {\n" " (void)s->i;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 's' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:2:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void f(int* a, int* b, int i) {\n" // #13072 " a[b[i]] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'b' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:1:21]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("int f(int* a, int* b, int i) {\n" // #13085 " a[*(b + i)] = 0;\n" " return *(b + i);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'b' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:1:20]: (style) Parameter 'b' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("struct S { int a; };\n" // #13286 @@ -4363,8 +4364,8 @@ class TestOther : public TestFixture { " --s;\n" " if (s->a >= 0) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 's' can be declared as pointer to const\n" - "[test.cpp:5]: (style) Parameter 's' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n", errout_str()); } @@ -4375,20 +4376,20 @@ class TestOther : public TestFixture { "void g(std::array& a) {\n" " a.fill(0);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'a' can be declared as const array\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:28]: (style) Parameter 'a' can be declared as const array [constParameterReference]\n", errout_str()); check("int f() {\n" " static int i[1] = {};\n" " return i[0];\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'i' can be declared as const array\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\n", errout_str()); check("int f() {\n" " static int i[] = { 0 };\n" " int j = i[0] + 1;\n" " return j;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'i' can be declared as const array\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (style) Variable 'i' can be declared as const array [constVariable]\n", errout_str()); check("void f(int i) {\n" " const char *tmp;\n" @@ -4399,8 +4400,8 @@ class TestOther : public TestFixture { " tmp = b[i];\n" " printf(\"%s\", tmp);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'a' can be declared as const array\n" - "[test.cpp:4]: (style) Variable 'b' can be declared as const array\n", + ASSERT_EQUALS("[test.cpp:3:11]: (style) Variable 'a' can be declared as const array [constVariable]\n" + "[test.cpp:4:18]: (style) Variable 'b' can be declared as const array [constVariable]\n", errout_str()); check("int f(int i, int j) {\n" // #13069 @@ -4411,7 +4412,7 @@ class TestOther : public TestFixture { " };\n" " return a[j][i];\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'a' can be declared as const array\n", + ASSERT_EQUALS("[test.cpp:2:9]: (style) Variable 'a' can be declared as const array [constVariable]\n", errout_str()); check("void f(int n, int v[42]) {\n" // #12796 @@ -4421,7 +4422,7 @@ class TestOther : public TestFixture { " if (j == 1) {}\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'v' can be declared as const array\n", + ASSERT_EQUALS("[test.cpp:1:19]: (style) Parameter 'v' can be declared as const array [constParameter]\n", errout_str()); } @@ -4438,7 +4439,7 @@ class TestOther : public TestFixture { " }\n" " bar(y);\n" "}"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo()\n" "{\n" @@ -4454,7 +4455,7 @@ class TestOther : public TestFixture { " }\n" " bar(y);\n" "}"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo()\n" "{\n" @@ -4583,7 +4584,7 @@ class TestOther : public TestFixture { " }\n" " bar(y);\n" "}"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:10]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void bar() {}\n" // bar isn't noreturn "void foo()\n" @@ -4599,7 +4600,7 @@ class TestOther : public TestFixture { " }\n" " bar(y);\n" "}"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo(int a) {\n" " char str[10];\n" @@ -4720,7 +4721,7 @@ class TestOther : public TestFixture { " }\n" " bar(y);\n" "}"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo()\n" "{\n" " int y = 1;\n" @@ -4735,7 +4736,7 @@ class TestOther : public TestFixture { " }\n" " bar(y);\n" "}"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo()\n" "{\n" " int y = 1;\n" @@ -4774,7 +4775,7 @@ class TestOther : public TestFixture { " }\n" " bar(y);\n" "}"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo()\n" "{\n" " int y = 1;\n" @@ -4789,7 +4790,7 @@ class TestOther : public TestFixture { " }\n" " bar(y);\n" "}"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo()\n" "{\n" " int y = 1;\n" @@ -4828,7 +4829,7 @@ class TestOther : public TestFixture { " }\n" " bar(y);\n" "}"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo()\n" "{\n" " int y = 1;\n" @@ -4843,7 +4844,7 @@ class TestOther : public TestFixture { " }\n" " bar(y);\n" "}"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo()\n" "{\n" " int y = 1;\n" @@ -4882,7 +4883,7 @@ class TestOther : public TestFixture { " }\n" " bar(y);\n" "}"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo()\n" "{\n" " int y = 1;\n" @@ -4897,7 +4898,7 @@ class TestOther : public TestFixture { " }\n" " bar(y);\n" "}"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo()\n" "{\n" " int y = 1;\n" @@ -5044,7 +5045,7 @@ class TestOther : public TestFixture { " }\n" " bar(y);\n" "}"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:10]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("bool f() {\n" " bool ret = false;\n" @@ -5062,9 +5063,9 @@ class TestOther : public TestFixture { " ret = true;\n" " return ret;\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:14]: (style) Variable 'ret' is reassigned a value before the old one has been used.\n" - "[test.cpp:8] -> [test.cpp:14]: (style) Variable 'ret' is reassigned a value before the old one has been used.\n" - "[test.cpp:11] -> [test.cpp:14]: (style) Variable 'ret' is reassigned a value before the old one has been used.\n", + ASSERT_EQUALS("[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\n" + "[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\n" + "[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\n", errout_str()); } @@ -5081,7 +5082,7 @@ class TestOther : public TestFixture { " break;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\n", errout_str()); check("void foo(int a)\n" "{\n" @@ -5095,7 +5096,7 @@ class TestOther : public TestFixture { " break;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\n", errout_str()); check("void foo(int a)\n" "{\n" @@ -5109,7 +5110,7 @@ class TestOther : public TestFixture { " break;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\n", errout_str()); check("void foo(int a)\n" "{\n" @@ -5169,7 +5170,7 @@ class TestOther : public TestFixture { " break;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:8]: (style) Variable 'y' is reassigned a value before the old one has been used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\n", errout_str()); check("void foo(int a)\n" "{\n" @@ -5183,7 +5184,7 @@ class TestOther : public TestFixture { " break;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\n", errout_str()); check("void foo(int a)\n" "{\n" @@ -5266,20 +5267,20 @@ class TestOther : public TestFixture { " }\n" " }\n" "}", true, false, false); - ASSERT_EQUALS("[test.cpp:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("int foo(int a) {\n" " return 0;\n" " return(a-1);\n" "}", true, false, false); - ASSERT_EQUALS("[test.cpp:3]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("int foo(int a) {\n" " A:" " return(0);\n" " goto A;\n" "}", true, false, false); - ASSERT_EQUALS("[test.cpp:3]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); constexpr char xmldata[] = "\n" "\n" @@ -5294,7 +5295,7 @@ class TestOther : public TestFixture { " exit(0);\n" " break;\n" "}", true, false, false, false, &settings); - ASSERT_EQUALS("[test.cpp:3]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("class NeonSession {\n" " void exit();\n" @@ -5326,7 +5327,7 @@ class TestOther : public TestFixture { " break;\n" " }\n" "}", true, false, false); - ASSERT_EQUALS("[test.cpp:7]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("void foo(int a)\n" "{\n" @@ -5350,7 +5351,7 @@ class TestOther : public TestFixture { " }\n" " }\n" "}", true, false, false); - ASSERT_EQUALS("[test.cpp:6]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("void foo(int a)\n" "{\n" @@ -5362,7 +5363,7 @@ class TestOther : public TestFixture { " a+=2;\n" " }\n" "}", true, false, false); - ASSERT_EQUALS("[test.cpp:6]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("void foo(int a)\n" "{\n" @@ -5379,13 +5380,13 @@ class TestOther : public TestFixture { " throw 0;\n" " return 1;\n" "}", true, false, false); - ASSERT_EQUALS("[test.cpp:3]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("void foo() {\n" " throw 0;\n" " return;\n" "}", true, false, false); - ASSERT_EQUALS("[test.cpp:3]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("int foo() {\n" " throw = 0;\n" @@ -5397,13 +5398,13 @@ class TestOther : public TestFixture { " return 0;\n" " return 1;\n" "}", true, false, false, false); - ASSERT_EQUALS("[test.cpp:3]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("int foo() {\n" " return 0;\n" " foo();\n" "}", true, false, false); - ASSERT_EQUALS("[test.cpp:3]: (style) Statements following 'return' will never be executed.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\n", errout_str()); check("int foo(int unused) {\n" " return 0;\n" @@ -5424,7 +5425,7 @@ class TestOther : public TestFixture { " (void)unused2;\n" " foo();\n" "}", true, false, false); - ASSERT_EQUALS("[test.cpp:5]: (style) Statements following 'return' will never be executed.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\n", errout_str()); check("int foo() {\n" " if(bar)\n" @@ -5442,7 +5443,7 @@ class TestOther : public TestFixture { " }\n" " return 124;\n" "}", true, false, false); - ASSERT_EQUALS("[test.cpp:4]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("void foo() {\n" " while(bar) {\n" @@ -5450,7 +5451,7 @@ class TestOther : public TestFixture { " break;\n" " }\n" "}", true, false, false); - ASSERT_EQUALS("[test.cpp:4]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); // #5707 check("extern int i,j;\n" @@ -5461,14 +5462,14 @@ class TestOther : public TestFixture { " return 0;\n" " j=2;\n" "}", true, false, false); - ASSERT_EQUALS("[test.cpp:7]: (style) Statements following 'return' will never be executed.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\n", errout_str()); check("int foo() {\n" " return 0;\n" " label:\n" " throw 0;\n" "}", true, false, false); - ASSERT_EQUALS("[test.cpp:3]: (style) Label 'label' is not used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\n", errout_str()); check("struct A {\n" " virtual void foo (P & Val) throw ();\n" @@ -5517,7 +5518,7 @@ class TestOther : public TestFixture { "\n" // #endif " return 1;\n" "}", true, true, false); - ASSERT_EQUALS("[test.cpp:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); // #4711 lambda functions check("int f() {\n" @@ -5613,13 +5614,13 @@ class TestOther : public TestFixture { " n();\n" " g();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Statements following noreturn function 'n()' will never be executed.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (style) Statements following noreturn function 'n()' will never be executed. [unreachableCode]\n", errout_str()); check("void f() {\n" " exit(1);\n" " g();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Statements following noreturn function 'exit()' will never be executed.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\n", errout_str()); check("void f() {\n" " do {\n" @@ -5627,7 +5628,7 @@ class TestOther : public TestFixture { " g();\n" " } while (0);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Statements following 'break' will never be executed.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (style) Statements following 'break' will never be executed. [unreachableCode]\n", errout_str()); check("void f() {\n" // #12244 " {\n" @@ -5636,7 +5637,7 @@ class TestOther : public TestFixture { " }\n" " std::cout << \"y\";\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (style) Statements following 'return' will never be executed.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\n", errout_str()); check("void f() {\n" " {\n" @@ -5645,7 +5646,7 @@ class TestOther : public TestFixture { " }\n" " std::cout << \"y\";\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (style) Statements following noreturn function 'exit()' will never be executed.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:5]: (style) Statements following noreturn function 'exit()' will never be executed. [unreachableCode]\n", errout_str()); check("int f() {\n" // #13475 " { return 0; };\n" @@ -5681,8 +5682,8 @@ class TestOther : public TestFixture { " }\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n" - "[test.cpp:1]: (style) Parameter 'argv' can be declared as const array\n", + ASSERT_EQUALS("[test.cpp:6:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n" + "[test.cpp:1:26]: (style) Parameter 'argv' can be declared as const array [constParameter]\n", errout_str()); check("int f(int i) {\n" // #13491 @@ -5744,7 +5745,7 @@ class TestOther : public TestFixture { " }\n" " return 3;\n" "}\n"); - TODO_ASSERT_EQUALS("[test.cpp:6]: (style) Statements following 'return' will never be executed.\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:6:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\n", "", errout_str()); check("int f() {\n" // #13472 " int var;\n" @@ -5775,7 +5776,7 @@ class TestOther : public TestFixture { " continue;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) 'continue' is redundant since it is the last statement in a loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\n", errout_str()); check("void f() {\n" " int i = 0;" @@ -5785,7 +5786,7 @@ class TestOther : public TestFixture { " continue;\n" " } while (i < 10);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (style) 'continue' is redundant since it is the last statement in a loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9]: (style) 'continue' is redundant since it is the last statement in a loop. [redundantContinue]\n", errout_str()); check("int f() {\n" // #13475 " { return 0; };\n" @@ -5812,7 +5813,7 @@ class TestOther : public TestFixture { " }\n" " return false;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (style) Statements following 'return' will never be executed.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9]: (style) Statements following 'return' will never be executed. [unreachableCode]\n", errout_str()); } @@ -5827,9 +5828,9 @@ class TestOther : public TestFixture { " foo();\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended.\n" - "[test.cpp:5]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended.\n" - "[test.cpp:7]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\n" + "[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\n" + "[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\n", errout_str()); check("void foo() {\n" " switch(a) {\n" @@ -5853,12 +5854,12 @@ class TestOther : public TestFixture { check("void foo(int c) {\n" " if (x) c == 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\n", errout_str()); check("void foo(const int* c) {\n" " if (x) *c == 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\n", errout_str()); check("void foo(int c) {\n" @@ -5871,7 +5872,7 @@ class TestOther : public TestFixture { check("void foo(int c) {\n" " c == 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\n", errout_str()); check("void foo(int c) {\n" " for (int i = 0; i == 10; i ++) {\n" @@ -5885,28 +5886,28 @@ class TestOther : public TestFixture { " c ++;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\n", errout_str()); check("void foo(int c) {\n" " for (i == 1; i < 10; i ++) {\n" " c ++;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\n", errout_str()); check("void foo(int c) {\n" " for (i == 2; i < 10; i ++) {\n" " c ++;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\n", errout_str()); check("void foo(int c) {\n" " for (int i = 0; i < 10; i == c) {\n" " c ++;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\n", errout_str()); check("void foo(int c) {\n" " for (; running == 1;) {\n" @@ -5928,7 +5929,7 @@ class TestOther : public TestFixture { check("void foo(int x) {\n" " printf(\"%i\", ({x == 0; x > 0 ? 10 : 20}));\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\n", errout_str()); check("void foo(int x) {\n" " for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\n" @@ -5958,16 +5959,16 @@ class TestOther : public TestFixture { " +g();\n" " -g();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Found suspicious operator '+', result is not used.\n" - "[test.cpp:4]: (warning, inconclusive) Found suspicious operator '-', result is not used.\n", + ASSERT_EQUALS("[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\n" + "[test.cpp:4:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\n", errout_str()); check("void f(int i) {\n" " +i;\n" " -i;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious operator '+', result is not used.\n" - "[test.cpp:3]: (warning, inconclusive) Found suspicious operator '-', result is not used.\n", + ASSERT_EQUALS("[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '+', result is not used. [constStatement]\n" + "[test.cpp:3:5]: (warning, inconclusive) Found suspicious operator '-', result is not used. [constStatement]\n", errout_str()); } @@ -5975,17 +5976,17 @@ class TestOther : public TestFixture { check("double f(double a, double b, float c) {\n" " return a + (float)b + c;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Floating-point cast causes loss of precision.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\n", errout_str()); check("double f(double a, double b, float c) {\n" " return a + static_cast(b) + c;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Floating-point cast causes loss of precision.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:34]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\n", errout_str()); check("long double f(long double a, long double b, float c) {\n" " return a + (double)b + c;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Floating-point cast causes loss of precision.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\n", errout_str()); check("void g(int, double);\n" "void h(double);\n" @@ -5993,8 +5994,8 @@ class TestOther : public TestFixture { " g(1, (float)d);\n" " h((float)d);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Floating-point cast causes loss of precision.\n" - "[test.cpp:5]: (style) Floating-point cast causes loss of precision.\n", + ASSERT_EQUALS("[test.cpp:4:10]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\n" + "[test.cpp:5:7]: (style) Floating-point cast causes loss of precision. [suspiciousFloatingPointCast]\n", errout_str()); } @@ -6005,26 +6006,26 @@ class TestOther : public TestFixture { " x = x;\n" " return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Redundant assignment of 'x' to itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\n", errout_str()); check("void foo()\n" "{\n" " int x = x;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Redundant assignment of 'x' to itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\n", errout_str()); check("struct A { int b; };\n" "void foo(A* a1, A* a2) {\n" " a1->b = a1->b;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Redundant assignment of 'a1->b' to itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\n", errout_str()); check("int x;\n" "void f()\n" "{\n" " x = x = 3;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Redundant assignment of 'x' to itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\n", errout_str()); // #4073 (segmentation fault) check("void Foo::myFunc( int a )\n" @@ -6052,7 +6053,7 @@ class TestOther : public TestFixture { " BAR *x = getx();\n" " x = x;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Redundant assignment of 'x' to itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\n", errout_str()); // #2502 - non-primitive type -> there might be some side effects check("void foo()\n" @@ -6084,7 +6085,7 @@ class TestOther : public TestFixture { "void f() {\n" " i = i;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Redundant assignment of 'i' to itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\n", errout_str()); // #4291 - id for variables accessed through 'this' check("class Foo {\n" @@ -6094,7 +6095,7 @@ class TestOther : public TestFixture { "void Foo::func() {\n" " this->var = var;\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (style) Redundant assignment of 'this->var' to itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\n", errout_str()); check("class Foo {\n" " int var;\n" @@ -6128,9 +6129,9 @@ class TestOther : public TestFixture { " }\n" " double x, y, z;\n" "};"); - ASSERT_EQUALS("[test.cpp:10]: (style) Redundant assignment of 'x' to itself.\n" - "[test.cpp:10]: (style) Redundant assignment of 'y' to itself.\n" - "[test.cpp:10]: (style) Redundant assignment of 'z' to itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\n" + "[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\n" + "[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\n", errout_str()); check("void f(int i) { i = !!i; }"); ASSERT_EQUALS("", errout_str()); @@ -6140,7 +6141,7 @@ class TestOther : public TestFixture { " int &ref = x;\n" " ref = x;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Redundant assignment of 'ref' to itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (style) Redundant assignment of 'ref' to itself. [selfAssignment]\n", errout_str()); check("class Foo {\n" // #9850 " int i{};\n" @@ -6199,7 +6200,7 @@ class TestOther : public TestFixture { " std::cout << \"hello\" << std::endl;\n" " return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:15]: (style) Instance of 'Lock' object is destroyed immediately.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\n", errout_str()); } void trac3693() { @@ -6245,7 +6246,7 @@ class TestOther : public TestFixture { " NotAFunction ( 123 );\n" " return 0 ;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Instance of 'NotAFunction' object is destroyed immediately.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\n", errout_str()); } void testMisusedScopeObjectPicksStruct() { @@ -6255,7 +6256,7 @@ class TestOther : public TestFixture { " NotAClass ( 123 ) ;\n" " return true ;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Instance of 'NotAClass' object is destroyed immediately.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\n", errout_str()); } void testMisusedScopeObjectDoesNotPickIf() { @@ -6306,7 +6307,7 @@ class TestOther : public TestFixture { " Foo();\n" " do_something();\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (style) Instance of 'Foo' object is destroyed immediately.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\n", errout_str()); } void testMisusedScopeObjectDoesNotPickUsedObject() { @@ -6334,7 +6335,7 @@ class TestOther : public TestFixture { "}\n"; check(code, true); - ASSERT_EQUALS("[test.cpp:7]: (style) Instance of 'cb_watch_bool' object is destroyed immediately.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\n", errout_str()); check(code, false); ASSERT_EQUALS("", errout_str()); @@ -6392,7 +6393,7 @@ class TestOther : public TestFixture { " Foo(char x, int y) { }\n" "};\n"; check(code, true); - ASSERT_EQUALS("[test.cpp:4]: (style) Instance of 'Foo' object is destroyed immediately.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\n", errout_str()); } void testMisusedScopeObjectStandardType() { @@ -6407,11 +6408,11 @@ class TestOther : public TestFixture { " int{ g() };\n" // don't warn " g();\n" "}\n", true); - ASSERT_EQUALS("[test.cpp:3]: (style) Instance of 'int' object is destroyed immediately.\n" - "[test.cpp:4]: (style) Instance of 'int' object is destroyed immediately.\n" - "[test.cpp:6]: (style) Instance of 'int' object is destroyed immediately.\n" - "[test.cpp:7]: (style) Instance of 'int' object is destroyed immediately.\n" - "[test.cpp:8]: (style) Instance of 'int' object is destroyed immediately.\n", + ASSERT_EQUALS("[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\n" + "[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\n" + "[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\n" + "[test.cpp:7:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\n" + "[test.cpp:8:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\n", errout_str()); check("void f(int j) {\n" @@ -6442,7 +6443,7 @@ class TestOther : public TestFixture { " M::N::S();\n" " return 0;\n" "}\n", true); - ASSERT_EQUALS("[test.cpp:7]: (style) Instance of 'M::N::S' object is destroyed immediately.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\n", errout_str()); check("void f() {\n" // #10057 " std::string(\"abc\");\n" @@ -6450,9 +6451,9 @@ class TestOther : public TestFixture { " std::pair(1, 2);\n" " (void)0;\n" "}\n", true); - ASSERT_EQUALS("[test.cpp:2]: (style) Instance of 'std::string' object is destroyed immediately.\n" - "[test.cpp:3]: (style) Instance of 'std::string' object is destroyed immediately.\n" - "[test.cpp:4]: (style) Instance of 'std::pair' object is destroyed immediately.\n", + ASSERT_EQUALS("[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\n" + "[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\n" + "[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\n", errout_str()); check("struct S {\n" // #10083 @@ -6467,9 +6468,9 @@ class TestOther : public TestFixture { " }\n" " std::mutex m;\n" "}\n", true); - ASSERT_EQUALS("[test.cpp:3]: (style) Instance of 'std::lock_guard' object is destroyed immediately.\n" - "[test.cpp:6]: (style) Instance of 'std::scoped_lock' object is destroyed immediately.\n" - "[test.cpp:9]: (style) Instance of 'std::scoped_lock' object is destroyed immediately.\n", + ASSERT_EQUALS("[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\n" + "[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\n" + "[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\n", errout_str()); check("struct S { int i; };\n" @@ -6489,7 +6490,7 @@ class TestOther : public TestFixture { "void t1() { g() = {}; }\n" "void t2() { h() = {}; }\n" "void t3() { *i() = {}; }\n", true); - ASSERT_EQUALS("[test.cpp:6]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\n", errout_str()); } void trac2084() { @@ -6518,12 +6519,12 @@ class TestOther : public TestFixture { check("int f(char c) {\n" " return 10 * (c == 0) ? 1 : 2;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for '*' and '?'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\n", errout_str()); check("void f(char c) {\n" " printf(\"%i\", 10 * (c == 0) ? 1 : 2);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for '*' and '?'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\n", errout_str()); check("void f() {\n" " return (2*a)?b:c;\n" @@ -6533,28 +6534,28 @@ class TestOther : public TestFixture { check("void f(char c) {\n" " printf(\"%i\", a + b ? 1 : 2);\n" "}",true,false,false); - ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for '+' and '?'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\n", errout_str()); check("void f() {\n" " std::cout << x << y ? 2 : 3;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for '<<' and '?'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\n", errout_str()); check("void f() {\n" " int ab = a - b ? 2 : 3;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for '-' and '?'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\n", errout_str()); check("void f() {\n" " int ab = a | b ? 2 : 3;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for '|' and '?'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\n", errout_str()); // ticket #195 check("int f(int x, int y) {\n" " return x >> ! y ? 8 : 2;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Clarify calculation precedence for '>>' and '?'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\n", errout_str()); check("int f() {\n" " return shift < sizeof(int64_t)*8 ? 1 : 2;\n" @@ -6589,8 +6590,8 @@ class TestOther : public TestFixture { " return c;\n" "}"); ASSERT_EQUALS( - "[test.cpp:2]: (warning, inconclusive) Found suspicious operator '*', result is not used.\n" - "[test.cpp:2]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'?\n", + "[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\n" + "[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\n", errout_str()); check("char* f(char** c) {\n" @@ -6598,32 +6599,32 @@ class TestOther : public TestFixture { " return *c;\n" "}"); ASSERT_EQUALS( - "[test.cpp:2]: (warning, inconclusive) Found suspicious operator '*', result is not used.\n" - "[test.cpp:2]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'?\n", + "[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\n" + "[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\n", errout_str()); check("void f(Foo f) {\n" " *f.a++;\n" "}"); ASSERT_EQUALS( - "[test.cpp:2]: (warning, inconclusive) Found suspicious operator '*', result is not used.\n" - "[test.cpp:2]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'?\n", + "[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\n" + "[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\n", errout_str()); check("void f(Foo f) {\n" " *f.a[5].v[3]++;\n" "}"); ASSERT_EQUALS( - "[test.cpp:2]: (warning, inconclusive) Found suspicious operator '*', result is not used.\n" - "[test.cpp:2]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'?\n", + "[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\n" + "[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\n", errout_str()); check("void f(Foo f) {\n" " *f.a(1, 5).v[x + y]++;\n" "}"); ASSERT_EQUALS( - "[test.cpp:2]: (warning, inconclusive) Found suspicious operator '*', result is not used.\n" - "[test.cpp:2]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'?\n", + "[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\n" + "[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\n", errout_str()); check("char* f(char* c) {\n" @@ -6642,8 +6643,8 @@ class TestOther : public TestFixture { " return c;\n" "}"); ASSERT_EQUALS( - "[test.cpp:2]: (warning, inconclusive) Found suspicious operator '*', result is not used.\n" - "[test.cpp:2]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'?\n", + "[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\n" + "[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\n", errout_str()); check("char** f(char*** c) {\n" @@ -6651,8 +6652,8 @@ class TestOther : public TestFixture { " return **c;\n" "}"); ASSERT_EQUALS( - "[test.cpp:2]: (warning, inconclusive) Found suspicious operator '*', result is not used.\n" - "[test.cpp:2]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'?\n", + "[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\n" + "[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\n", errout_str()); check("char*** f(char*** c) {\n" @@ -6694,7 +6695,7 @@ class TestOther : public TestFixture { " else\n" " b = 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Found duplicate branches for 'if' and 'else'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\n", errout_str()); check("void f(int a, int &b) {\n" " if (a) {\n" @@ -6705,7 +6706,7 @@ class TestOther : public TestFixture { " } else\n" " b = 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\n", errout_str()); check("void f(int a, int &b) {\n" " if (a == 1)\n" @@ -6717,7 +6718,7 @@ class TestOther : public TestFixture { " b = 2;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\n", errout_str()); check("int f(int signed, unsigned char value) {\n" " int ret;\n" @@ -6743,7 +6744,7 @@ class TestOther : public TestFixture { " else\n" " __asm__(\"mov ax, bx\");\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Found duplicate branches for 'if' and 'else'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\n", errout_str()); } void duplicateBranch1() { @@ -6757,7 +6758,7 @@ class TestOther : public TestFixture { " else\n" " frac = front/(front-back);\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\n", errout_str()); check("void f()\n" "{\n" @@ -6766,7 +6767,7 @@ class TestOther : public TestFixture { " else\n" " frac = front/((front-back));\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\n", errout_str()); // No message about empty branches (#5354) check("void f()\n" @@ -6800,8 +6801,8 @@ class TestOther : public TestFixture { " x = j;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5] -> [test.cpp:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'.\n" - "[test.cpp:2]: (style) The scope of the variable 'j' can be reduced.\n", + ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\n" + "[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\n", errout_str()); check("void f(bool b, int i) {\n" @@ -6838,7 +6839,7 @@ class TestOther : public TestFixture { " j = i;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\n", errout_str()); check("void f(bool b) {\n" " int j;\n" @@ -6897,7 +6898,7 @@ class TestOther : public TestFixture { check("void foo(int a) {\n" " if (a == a) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '=='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\n", errout_str()); check("void fun(int b) {\n" " return a && a ||\n" @@ -6906,50 +6907,50 @@ class TestOther : public TestFixture { " e < e &&\n" " f ;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '&&'.\n" - "[test.cpp:3]: (style) Same expression on both sides of '=='.\n" - "[test.cpp:4]: (style) Same expression on both sides of '>'.\n" - "[test.cpp:5]: (style) Same expression on both sides of '<'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\n" + "[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\n" + "[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\n" + "[test.cpp:5:15]: (style) Same expression on both sides of '<'. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " return a && a;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '&&'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " a = b && b;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '&&'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\n", errout_str()); check("void foo(int b) {\n" " f(a,b == b);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '=='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\n", errout_str()); check("void foo(int b) {\n" " f(b == b, a);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '=='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if (x!=2 || x!=2) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '||'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\n", errout_str()); check("void foo(int a, int b) {\n" " if ((a < b) && (b > a)) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '&&' because 'aa' represent the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void foo(int a, int b) {\n" " if ((a <= b) && (b >= a)) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" " if (x!=2 || y!=3 || x!=2) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if (x!=2 && (x=y) && x!=2) {}\n" @@ -6959,7 +6960,7 @@ class TestOther : public TestFixture { check("void foo() {\n" " if (a && b || a && b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '||'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if (a && b || b && c) {}\n" @@ -6969,22 +6970,22 @@ class TestOther : public TestFixture { check("void foo() {\n" " if (a && b | b && c) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '|'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if ((a + b) | (a + b)) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '|'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if ((a | b) & (a | b)) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '&'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\n", errout_str()); check("void foo(int a, int b) {\n" " if ((a | b) == (a | b)) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '=='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if (a1[a2[c & 0xff] & 0xff]) {}\n" @@ -7008,12 +7009,12 @@ class TestOther : public TestFixture { check("void foo() {\n" " if (a && b && b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '&&'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if (a || b || b) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '||'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if (a / 1000 / 1000) {}\n" @@ -7023,7 +7024,7 @@ class TestOther : public TestFixture { check("int foo(int i) {\n" " return i/i;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '/'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if (a << 1 << 1) {}\n" @@ -7049,7 +7050,7 @@ class TestOther : public TestFixture { // #5535: Reference named like its type check("void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Variable 'UMSConfig' can be declared as reference to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\n", errout_str()); // #3868 - false positive (same expression on both sides of |) check("void f(int x) {\n" @@ -7062,13 +7063,13 @@ class TestOther : public TestFixture { " bool a = bar.isSet() && bar->isSet();\n" " bool b = bar.isSet() && bar.isSet();\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Same expression on both sides of '&&'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\n", errout_str()); check("void foo(int a, int b) {\n" " if ((b + a) | (a + b)) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\n", errout_str()); check("void foo(const std::string& a, const std::string& b) {\n" " return a.find(b+\"&\") || a.find(\"&\"+b);\n" @@ -7083,19 +7084,19 @@ class TestOther : public TestFixture { check("void foo(double a, double b) {\n" " if ((b + a) > (a + b)) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" " if ((x == 1) && (x == 0x00000001))\n" " a++;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " enum { Four = 4 };\n" " if (Four == 4) {}" "}", true, true, false); - ASSERT_EQUALS("[test.cpp:3]: (style) The comparison 'Four == 4' is always true.\n", + ASSERT_EQUALS("[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" @@ -7121,7 +7122,7 @@ class TestOther : public TestFixture { " enum { FourInEnumTwo = 4 };\n" " if (FourInEnumOne == FourInEnumTwo) {}\n" "}", true, true, false); - ASSERT_EQUALS("[test.cpp:4]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value.\n", + ASSERT_EQUALS("[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" @@ -7135,7 +7136,7 @@ class TestOther : public TestFixture { " if (sizeof(a) == sizeof(a)) { }\n" " if (sizeof(a) == sizeof(b)) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '=='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\n", errout_str()); check("float bar(int) __attribute__((pure));\n" "char foo(int) __attribute__((pure));\n" @@ -7144,7 +7145,7 @@ class TestOther : public TestFixture { " if (unknown(a) == unknown(a)) { }\n" " if (foo(a) == foo(a)) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (style) Same expression on both sides of '=='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\n", errout_str()); } void duplicateExpression2() { // check if float is NaN or Inf @@ -7168,7 +7169,7 @@ class TestOther : public TestFixture { check("struct X { int i; };\n" "int f(struct X x) { return x.i == x.i; }"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '=='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\n", errout_str()); // #5284 - when type is unknown, assume it's float check("int f() { return x==x; }"); @@ -7198,7 +7199,7 @@ class TestOther : public TestFixture { "void A::foo() const {\n" " if (bar() && bar()) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (style) Same expression on both sides of '&&'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\n", errout_str()); check("struct A {\n" " void foo();\n" @@ -7222,7 +7223,7 @@ class TestOther : public TestFixture { " if (b.bar(1) && b.bar(1)) {}\n" " if (a.bar(1) && a.bar(1)) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:11]: (style) Same expression on both sides of '&&'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\n", errout_str()); check("class D { void strcmp(); };\n" "void foo() {\n" @@ -7234,7 +7235,7 @@ class TestOther : public TestFixture { check("void foo() {\n" " if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\n" "}", true, false, true, false, &settings); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '||'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\n", errout_str()); check("void GetValue() { return rand(); }\n" "void foo() {\n" @@ -7246,19 +7247,19 @@ class TestOther : public TestFixture { "void foo() {\n" " if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Same expression on both sides of '||'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\n", errout_str()); check("void GetValue() __attribute__((const));\n" "void GetValue() { return X; }\n" "void foo() {\n" " if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Same expression on both sides of '||'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if (str == \"(\" || str == \"(\") {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '||'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\n" @@ -7275,7 +7276,7 @@ class TestOther : public TestFixture { check("void f(A *src) {\n" " if (dynamic_cast(src) || dynamic_cast(src)) {}\n" "}\n", true, false, false); // don't run simplifications - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '||'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\n", errout_str()); // #5819 check("Vector func(Vector vec1) {\n" @@ -7287,8 +7288,8 @@ class TestOther : public TestFixture { " return fabs(vec1 & vec1 & vec1);\n" "}"); ASSERT_EQUALS( - "[test.cpp:2]: (style) Same expression on both sides of '&'.\n" - "[test.cpp:2]: (style) Same expression on both sides of '&'.\n", // duplicate + "[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\n" + "[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\n", // duplicate errout_str()); } @@ -7323,7 +7324,7 @@ class TestOther : public TestFixture { " if (X == X) {}\n" " if (X == Y) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Same expression on both sides of '=='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\n", errout_str()); checkP("#define X 1\n" "#define Y X\n" @@ -7345,13 +7346,13 @@ class TestOther : public TestFixture { " const int i = sizeof(int);\n" " if ( i != sizeof (int)){}\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " const int i = sizeof(int);\n" " if ( sizeof (int) != i){}\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void f(int a = 1) { if ( a != 1){}}"); ASSERT_EQUALS("", errout_str()); @@ -7360,21 +7361,21 @@ class TestOther : public TestFixture { " int a = 1;\n" " if ( a != 1){}\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'a != 1' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " int a = 1;\n" " int b = 1;\n" " if ( a != b){}\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3] -> [test.cpp:4]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " int a = 1;\n" " int b = a;\n" " if ( a != b){}\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void use(int);\n" "void f() {\n" @@ -7383,7 +7384,7 @@ class TestOther : public TestFixture { " use(b);\n" " if ( a != 1){}\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) The comparison 'a != 1' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void use(int);\n" "void f() {\n" @@ -7407,7 +7408,7 @@ class TestOther : public TestFixture { "void f() {\n" " if ( a != 1){}\n" "}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:3]: (style) The comparison 'a != 1' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\n", errout_str()); check("int a = 1;\n" " void f() {\n" @@ -7419,7 +7420,7 @@ class TestOther : public TestFixture { " static const int a = 1;\n" " if ( a != 1){}\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'a != 1' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " static int a = 1;\n" @@ -7432,7 +7433,7 @@ class TestOther : public TestFixture { " if ( a != 1){\n" " a++;\n" " }}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'a != 1' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void f(int b) {\n" " int a = 1;\n" @@ -7447,7 +7448,7 @@ class TestOther : public TestFixture { " const bool c = a;\n" " return a && b && c;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value.\n", + ASSERT_EQUALS("[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\n", errout_str()); // 6906 @@ -7455,13 +7456,13 @@ class TestOther : public TestFixture { " const bool b1 = !b;\n" " if(!b && b1){}\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\n", errout_str()); // 7284 check("void f(void) {\n" " if (a || !!a) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\n", errout_str()); // 8205 check("void f(int x) {\n" @@ -7472,7 +7473,7 @@ class TestOther : public TestFixture { " break;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (style) The comparison 'Diag == 0' is always true.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\n", errout_str()); // #9744 check("void f(const std::vector& ints) {\n" @@ -7481,7 +7482,7 @@ class TestOther : public TestFixture { " if (p == 0) {}\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) The comparison 'p == 0' is always true.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:18] -> [test.cpp:4:15]: (style) The comparison 'p == 0' is always true. [knownConditionTrueFalse]\n", errout_str()); // #11820 check("unsigned f(unsigned x) {\n" @@ -7616,7 +7617,7 @@ class TestOther : public TestFixture { " int var = buffer[index - 1];\n" " return buffer[index - 1] - var;\n" // << "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\n", errout_str()); } void duplicateExpression13() { //#7899 @@ -7633,7 +7634,7 @@ class TestOther : public TestFixture { " int* g = &k;\n" " return (f + 4 != g + 4);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4] -> [test.cpp:5]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:5:19]: (style) The comparison 'f+4 != g+4' is always false because 'f+4' and 'g+4' represent the same value. [knownConditionTrueFalse]\n", errout_str()); } void duplicateExpression15() { //#10650 @@ -7645,8 +7646,8 @@ class TestOther : public TestFixture { " const int i = int{ 0 };\n" " return i == 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'i == 0' is always true.\n" - "[test.cpp:6] -> [test.cpp:7]: (style) The comparison 'i == 0' is always true.\n", + ASSERT_EQUALS("[test.cpp:2:22] -> [test.cpp:3:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\n" + "[test.cpp:6:22] -> [test.cpp:7:14]: (style) The comparison 'i == 0' is always true. [knownConditionTrueFalse]\n", errout_str()); } @@ -7669,9 +7670,9 @@ class TestOther : public TestFixture { " (a == \"y\") ||\n" " (a == \"42\")) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:4]: (style) Same expression 'a==\"42\"' found multiple times in chain of '||' operators.\n" - "[test.cpp:7] -> [test.cpp:9]: (style) Same expression 'a==\"42\"' found multiple times in chain of '||' operators.\n" - "[test.cpp:13] -> [test.cpp:16]: (style) Same expression 'a==\"42\"' found multiple times in chain of '||' operators.\n", + ASSERT_EQUALS("[test.cpp:1:28] -> [test.cpp:4:20]: (style) Same expression 'a==\"42\"' found multiple times in chain of '||' operators. [duplicateExpression]\n" + "[test.cpp:7:28] -> [test.cpp:9:20]: (style) Same expression 'a==\"42\"' found multiple times in chain of '||' operators. [duplicateExpression]\n" + "[test.cpp:13:28] -> [test.cpp:16:20]: (style) Same expression 'a==\"42\"' found multiple times in chain of '||' operators. [duplicateExpression]\n", errout_str()); check("void f(const char* s) {\n" // #6371 @@ -7680,7 +7681,7 @@ class TestOther : public TestFixture { " break;\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:28]: (style) Same expression '!s[1]' found multiple times in chain of '||' operators. [duplicateExpression]\n", errout_str()); } void duplicateExpression17() { @@ -7690,9 +7691,9 @@ class TestOther : public TestFixture { " if (E0 > 0) {}\n" " if (E0 == 0) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) The comparison '0 > E0' is always false.\n" - "[test.cpp:4]: (style) The comparison 'E0 > 0' is always false.\n" - "[test.cpp:5]: (style) The comparison 'E0 == 0' is always true.\n", + ASSERT_EQUALS("[test.cpp:3:11]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\n" + "[test.cpp:4:12]: (style) The comparison 'E0 > 0' is always false. [knownConditionTrueFalse]\n" + "[test.cpp:5:12]: (style) The comparison 'E0 == 0' is always true. [knownConditionTrueFalse]\n", errout_str()); check("struct S {\n" // #12040, #12044 @@ -7711,13 +7712,13 @@ class TestOther : public TestFixture { " if (0 > S::E0) {}\n" " if (0 > S::F::F0) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:6]: (style) The comparison '0 > I' is always false.\n" - "[test.cpp:2] -> [test.cpp:7]: (style) The comparison '0 > S::I' is always false.\n" - "[test.cpp:8]: (style) The comparison '0 > E0' is always false.\n" - "[test.cpp:9]: (style) The comparison '0 > S::E0' is always false.\n" - "[test.cpp:2] -> [test.cpp:13]: (style) The comparison '0 > S::I' is always false.\n" - "[test.cpp:14]: (style) The comparison '0 > S::E0' is always false.\n" - "[test.cpp:15]: (style) The comparison '0 > S::F::F0' is always false.\n", + ASSERT_EQUALS("[test.cpp:2:26] -> [test.cpp:6:15]: (style) The comparison '0 > I' is always false. [knownConditionTrueFalse]\n" + "[test.cpp:2:26] -> [test.cpp:7:15]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\n" + "[test.cpp:8:15]: (style) The comparison '0 > E0' is always false. [knownConditionTrueFalse]\n" + "[test.cpp:9:15]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\n" + "[test.cpp:2:26] -> [test.cpp:13:11]: (style) The comparison '0 > S::I' is always false. [knownConditionTrueFalse]\n" + "[test.cpp:14:11]: (style) The comparison '0 > S::E0' is always false. [knownConditionTrueFalse]\n" + "[test.cpp:15:11]: (style) The comparison '0 > S::F::F0' is always false. [knownConditionTrueFalse]\n", errout_str()); check("template\n" // #12122 @@ -7750,7 +7751,7 @@ class TestOther : public TestFixture { " int a = 1;\n" " while ( a != 1){}\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'a != 1' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void f() { int a = 1; while ( a != 1){ a++; }}"); ASSERT_EQUALS("", errout_str()); @@ -7766,7 +7767,7 @@ class TestOther : public TestFixture { " if( i != 0 ) {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'i != 0' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " for(int i = 0; i < 10;) {\n" @@ -7807,7 +7808,7 @@ class TestOther : public TestFixture { " b++;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) The comparison 'a != 1' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\n", errout_str()); check("struct T {\n" // #11083 " std::string m;\n" @@ -7841,13 +7842,13 @@ class TestOther : public TestFixture { check("void f() {\n" " return A ? x : x;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression in both branches of ternary operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\n", errout_str()); check("int f(bool b, int a) {\n" " const int c = a;\n" " return b ? a : c;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Same expression in both branches of ternary operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\n", errout_str()); check("void f() {\n" " return A ? x : z;\n" @@ -7876,7 +7877,7 @@ class TestOther : public TestFixture { settings.platform.sizeof_long = 4; settings.platform.long_bit = 32; check(code, &settings); - ASSERT_EQUALS("[test.cpp:2]: (style) Same value in both branches of ternary operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\n", errout_str()); settings.platform.sizeof_long = 8; settings.platform.long_bit = 64; @@ -7889,31 +7890,31 @@ class TestOther : public TestFixture { check("void f() {\n" " if( a ? (b ? false:false): false ) ;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same value in both branches of ternary operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:23]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\n", errout_str()); check("int f1(int a) {return (a == 1) ? (int)1 : 1; }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Same value in both branches of ternary operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\n", errout_str()); check("int f2(int a) {return (a == 1) ? (int)1 : (int)1; }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Same value in both branches of ternary operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\n", errout_str()); check("int f3(int a) {return (a == 1) ? 1 : (int)1; }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Same value in both branches of ternary operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\n", errout_str()); check("int f4(int a) {return (a == 1) ? 1 : 1; }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Same value in both branches of ternary operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\n", errout_str()); check("int f5(int a) {return (a == (int)1) ? (int)1 : 1; }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Same value in both branches of ternary operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\n", errout_str()); check("int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Same value in both branches of ternary operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\n", errout_str()); check("int f7(int a) {return (a == (int)1) ? 1 : (int)1; }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Same value in both branches of ternary operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\n", errout_str()); check("int f8(int a) {return (a == (int)1) ? 1 : 1; }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Same value in both branches of ternary operator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\n", errout_str()); check("struct Foo {\n" " std::vector bar{1,2,3};\n" @@ -7996,32 +7997,32 @@ class TestOther : public TestFixture { check("void f(const int* x, bool b) {\n" " if ((x && b) || (x != 0 && b)) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'x!=0&&b' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void f(const int* x, bool b) {\n" " if ((x != 0 && b) || (x && b)) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x!=0&&b' and 'x&&b' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void f(const int* x, bool b) {\n" " if ((x && b) || (b && x != 0)) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18]: (style) Same expression on both sides of '||' because 'x&&b' and 'b&&x!=0' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void f(const int* x, bool b) {\n" " if ((!x && b) || (x == 0 && b)) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'x==0&&b' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void f(const int* x, bool b) {\n" " if ((x == 0 && b) || (!x && b)) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:23]: (style) Same expression on both sides of '||' because 'x==0&&b' and '!x&&b' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void f(const int* x, bool b) {\n" " if ((!x && b) || (b && x == 0)) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:19]: (style) Same expression on both sides of '||' because '!x&&b' and 'b&&x==0' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("struct A {\n" " int* getX() const;\n" @@ -8030,7 +8031,7 @@ class TestOther : public TestFixture { " if ((getX() && getB()) || (getX() != 0 && getB())) {}\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:5]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:32]: (style) Same expression on both sides of '||' because 'getX()&&getB()' and 'getX()!=0&&getB()' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void f(const int* x, bool b) {\n" " if ((x && b) || (x == 0 && b)) {}\n" @@ -8045,50 +8046,50 @@ class TestOther : public TestFixture { void oppositeExpression() { check("void f(bool a) { if(a && !a) {} }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Opposite expression on both sides of '&&'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\n", errout_str()); check("void f(bool a) { if(a != !a) {} }"); - ASSERT_EQUALS("[test.cpp:1]: (style) Opposite expression on both sides of '!='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\n", errout_str()); check("void f(bool a) { if( a == !(a) ) {}}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Opposite expression on both sides of '=='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\n", errout_str()); check("void f(bool a) { if( a != !(a) ) {}}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Opposite expression on both sides of '!='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\n", errout_str()); check("void f(bool a) { if( !(a) == a ) {}}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Opposite expression on both sides of '=='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\n", errout_str()); check("void f(bool a) { if( !(a) != a ) {}}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Opposite expression on both sides of '!='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\n", errout_str()); check("void f(bool a) { if( !(!a) == !(a) ) {}}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Opposite expression on both sides of '=='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\n", errout_str()); check("void f(bool a) { if( !(!a) != !(a) ) {}}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Opposite expression on both sides of '!='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\n", errout_str()); check("void f1(bool a) {\n" " const bool b = a;\n" " if( a == !(b) ) {}\n" " if( b == !(a) ) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Opposite expression on both sides of '=='.\n" - "[test.cpp:2] -> [test.cpp:4]: (style) Opposite expression on both sides of '=='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\n" + "[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\n", errout_str()); check("void f2(const bool *a) {\n" " const bool b = *a;\n" " if( *a == !(b) ) {}\n" " if( b == !(*a) ) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Opposite expression on both sides of '=='.\n" - "[test.cpp:2] -> [test.cpp:4]: (style) Opposite expression on both sides of '=='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\n" + "[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\n", errout_str()); check("void f(bool a) { a = !a; }"); ASSERT_EQUALS("", errout_str()); check("void f(int a) { if( a < -a ) {}}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Opposite expression on both sides of '<'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\n", errout_str()); check("void f(int a) { a -= -a; }"); ASSERT_EQUALS("", errout_str()); @@ -8134,25 +8135,25 @@ class TestOther : public TestFixture { " const bool b = a[42];\n" " if( b == !(a[42]) ) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Opposite expression on both sides of '=='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:21] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\n", errout_str()); check("void f(const bool *a) {\n" " const bool b = a[42];\n" " if( a[42] == !(b) ) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Opposite expression on both sides of '=='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:21] -> [test.cpp:3:15]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\n", errout_str()); check("void f(const bool *a) {\n" " const bool b = *a;\n" " if( b == !(*a) ) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Opposite expression on both sides of '=='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\n", errout_str()); check("void f(const bool *a) {\n" " const bool b = *a;\n" " if( *a == !(b) ) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Opposite expression on both sides of '=='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\n", errout_str()); check("void f(uint16_t u) {\n" // #9342 " if (u != (u & -u))\n" @@ -8171,7 +8172,7 @@ class TestOther : public TestFixture { " int i = f();\n" " int j = f();\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4]: (style) Same expression used in consecutive assignments of 'i' and 'j'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("struct Foo { int f() const; int g() const; };\n" "void test() {\n" @@ -8179,7 +8180,7 @@ class TestOther : public TestFixture { " int i = f.f();\n" " int j = f.f();\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4]: (style) Same expression used in consecutive assignments of 'i' and 'j'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("struct Foo { int f() const; int g() const; };\n" "void test() {\n" @@ -8188,7 +8189,7 @@ class TestOther : public TestFixture { " int i = f.f();\n" " int j = f.f();\n" "}"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:5]: (style) Same expression used in consecutive assignments of 'i' and 'j'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("int f() __attribute__((pure));\n" "int g() __attribute__((pure));\n" @@ -8196,7 +8197,7 @@ class TestOther : public TestFixture { " int i = 1 + f();\n" " int j = 1 + f();\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4]: (style) Same expression used in consecutive assignments of 'i' and 'j'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("int f() __attribute__((pure));\n" "int g() __attribute__((pure));\n" @@ -8221,7 +8222,7 @@ class TestOther : public TestFixture { " int i = f() + f();\n" " int j = f() + f();\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4]: (style) Same expression used in consecutive assignments of 'i' and 'j'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("int f(int) __attribute__((pure));\n" "int g(int) __attribute__((pure));\n" @@ -8229,7 +8230,7 @@ class TestOther : public TestFixture { " int i = f(0);\n" " int j = f(0);\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4]: (style) Same expression used in consecutive assignments of 'i' and 'j'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("int f(int) __attribute__((pure));\n" "int g(int) __attribute__((pure));\n" @@ -8244,14 +8245,14 @@ class TestOther : public TestFixture { " int i = *p;\n" " int j = *p;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (style) Same expression used in consecutive assignments of 'i' and 'j'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("struct A { int x; int y; };" "void test(A a) {\n" " int i = a.x;\n" " int j = a.x;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (style) Same expression used in consecutive assignments of 'i' and 'j'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("void test() {\n" " int i = 0;\n" @@ -8300,7 +8301,7 @@ class TestOther : public TestFixture { " int i = f.f();\n" " int j = f.f();\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("struct Foo { int f(); int g(); };\n" "void test() {\n" @@ -8353,8 +8354,8 @@ class TestOther : public TestFixture { " int start = x->first;\n" " int end = x->first;\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'.\n" - "[test.cpp:2]: (style) Parameter 'x' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\n" + "[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("struct SW { int first; };\n" @@ -8362,8 +8363,8 @@ class TestOther : public TestFixture { " int start = x->first;\n" " int end = x->first;\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'.\n" - "[test.cpp:2]: (style) Parameter 'x' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\n" + "[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("struct Foo { int f() const; };\n" @@ -8372,13 +8373,13 @@ class TestOther : public TestFixture { " int i = f.f();\n" " int j = f.f();\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("void test(const int * p) {\n" " int i = *p;\n" " int j = *p;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("struct Foo { int f() const; int g(int) const; };\n" "void test() {\n" @@ -8386,7 +8387,7 @@ class TestOther : public TestFixture { " int i = f.f();\n" " int j = f.f();\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("struct Foo { int f() const; };\n" "void test() {\n" @@ -8394,7 +8395,7 @@ class TestOther : public TestFixture { " int i = f.f();\n" " int j = f.f();\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); } void duplicateVarExpressionAssign() { @@ -8406,7 +8407,7 @@ class TestOther : public TestFixture { " use(i);\n" " i = j;\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("struct A { int x; int y; };" "void use(int);\n" @@ -8416,7 +8417,7 @@ class TestOther : public TestFixture { " use(j);\n" " j = i;\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("struct A { int x; int y; };" "void use(int);\n" @@ -8427,8 +8428,8 @@ class TestOther : public TestFixture { " if (i == j) {}\n" "}"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:3]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'.\n" - "[test.cpp:3] -> [test.cpp:4] -> [test.cpp:6]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value.\n", + "[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n" + "[test.cpp:3:14] -> [test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'i == j' is always true because 'i' and 'j' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("struct A { int x; int y; };" @@ -8440,8 +8441,8 @@ class TestOther : public TestFixture { " if (i == a.x) {}\n" "}"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:3]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'.\n" - "[test.cpp:3] -> [test.cpp:6]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value.\n", + "[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n" + "[test.cpp:3:14] -> [test.cpp:6:11]: (style) The comparison 'i == a.x' is always true because 'i' and 'a.x' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("struct A { int x; int y; };" @@ -8453,8 +8454,8 @@ class TestOther : public TestFixture { " if (j == a.x) {}\n" "}"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:3]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'.\n" - "[test.cpp:4] -> [test.cpp:6]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value.\n", + "[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n" + "[test.cpp:4:14] -> [test.cpp:6:11]: (style) The comparison 'j == a.x' is always true because 'j' and 'a.x' represent the same value. [knownConditionTrueFalse]\n", errout_str()); // Issue #8612 @@ -8484,7 +8485,7 @@ class TestOther : public TestFixture { " previous = current;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:16] -> [test.cpp:15]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\n", errout_str()); } void duplicateVarExpressionCrash() { @@ -8500,7 +8501,7 @@ class TestOther : public TestFixture { " (void)a;\n" " (void)b;\n" "}"); - ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:7]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\n", errout_str()); // Issue #8712 check("void f() {\n" @@ -8547,7 +8548,7 @@ class TestOther : public TestFixture { " return e + f;\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:5]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:20] -> [test.cpp:5:9]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'. [duplicateAssignExpression]\n", errout_str()); } void multiConditionSameExpression() { @@ -8556,8 +8557,8 @@ class TestOther : public TestFixture { " if (val < 0) continue;\n" " if ((val > 0)) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'val < 0' is always false.\n" - "[test.cpp:2] -> [test.cpp:4]: (style) The comparison 'val > 0' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\n" + "[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " int val = 0;\n" @@ -8567,7 +8568,7 @@ class TestOther : public TestFixture { " if ((*p > 0)) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3]: (style) Variable 'p' can be declared as pointer to const\n", + "[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\n", errout_str()); check("void f() {\n" @@ -8578,7 +8579,7 @@ class TestOther : public TestFixture { "}\n"); TODO_ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison '*p < 0' is always false.\n" "[test.cpp:2] -> [test.cpp:4]: (style) The comparison '*p > 0' is always false.\n", - "[test.cpp:3]: (style) Variable 'p' can be declared as pointer to const\n", + "[test.cpp:3:8]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\n", errout_str()); check("void f() {\n" @@ -8587,8 +8588,8 @@ class TestOther : public TestFixture { " if ((val > 0)) {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'val < 0' is always false.\n" - "[test.cpp:2] -> [test.cpp:4]: (style) The comparison 'val > 0' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\n" + "[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " int val = 0;\n" @@ -8596,8 +8597,8 @@ class TestOther : public TestFixture { " if ((val < 0)) {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'val < 0' is always false.\n" - "[test.cpp:2] -> [test.cpp:4]: (style) The comparison 'val < 0' is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\n" + "[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " int activate = 0;\n" @@ -8612,27 +8613,27 @@ class TestOther : public TestFixture { check("void foo() {\n" " for(unsigned char i = 10; i >= 0; i--) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\n", errout_str()); check("void foo(bool b) {\n" " for(unsigned int i = 10; b || i >= 0; i--) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\n", errout_str()); { const char code[] = "void foo(unsigned int x) {\n" " if (x < 0) {}\n" "}"; check(code, true, false, true, false); - ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check(code, true, false, true, true); - ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); } check("void foo(unsigned int x) {\n" " if (x < 0u) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check("void foo(int x) {\n" " if (x < 0) {}\n" @@ -8645,9 +8646,9 @@ class TestOther : public TestFixture { " if (x < y) {}\n" "}"; check(code, true, false, true, false); - ASSERT_EQUALS("[test.cpp:3]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check(code, true, false, true, true); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); } check("void foo(unsigned x) {\n" " int y = 0;\n" @@ -8660,12 +8661,12 @@ class TestOther : public TestFixture { check("void foo(unsigned int x) {\n" " if (0 > x) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check("void foo(unsigned int x) {\n" " if (0UL > x) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check("void foo(int x) {\n" " if (0 > x) {}\n" @@ -8675,17 +8676,17 @@ class TestOther : public TestFixture { check("void foo(unsigned int x) {\n" " if (x >= 0) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\n", errout_str()); check("void foo(unsigned int x, unsigned y) {\n" " if (x - y >= 0) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\n", errout_str()); check("void foo(unsigned int x) {\n" " if (x >= 0ull) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\n", errout_str()); check("void foo(int x) {\n" " if (x >= 0) {}\n" @@ -8695,12 +8696,12 @@ class TestOther : public TestFixture { check("void foo(unsigned int x) {\n" " if (0 <= x) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\n", errout_str()); check("void foo(unsigned int x) {\n" " if (0ll <= x) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\n", errout_str()); check("void foo(int x) {\n" " if (0 <= x) {}\n" @@ -8710,7 +8711,7 @@ class TestOther : public TestFixture { check("void foo(unsigned int x, bool y) {\n" " if (x < 0 && y) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check("void foo(int x, bool y) {\n" " if (x < 0 && y) {}\n" @@ -8720,7 +8721,7 @@ class TestOther : public TestFixture { check("void foo(unsigned int x, bool y) {\n" " if (0 > x && y) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check("void foo(int x, bool y) {\n" " if (0 > x && y) {}\n" @@ -8730,7 +8731,7 @@ class TestOther : public TestFixture { check("void foo(unsigned int x, bool y) {\n" " if (x >= 0 && y) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\n", errout_str()); check("void foo(int x, bool y) {\n" " if (x >= 0 && y) {}\n" @@ -8741,7 +8742,7 @@ class TestOther : public TestFixture { check("void foo(unsigned int x, bool y) {\n" " if (y && x < 0) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check("void foo(int x, bool y) {\n" " if (y && x < 0) {}\n" @@ -8751,7 +8752,7 @@ class TestOther : public TestFixture { check("void foo(unsigned int x, bool y) {\n" " if (y && 0 > x) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check("void foo(int x, bool y) {\n" " if (y && 0 > x) {}\n" @@ -8761,7 +8762,7 @@ class TestOther : public TestFixture { check("void foo(unsigned int x, bool y) {\n" " if (y && x >= 0) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\n", errout_str()); check("void foo(int x, bool y) {\n" " if (y && x >= 0) {}\n" @@ -8772,7 +8773,7 @@ class TestOther : public TestFixture { check("void foo(unsigned int x, bool y) {\n" " if (x < 0 || y) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check("void foo(int x, bool y) {\n" " if (x < 0 || y) {}\n" @@ -8782,7 +8783,7 @@ class TestOther : public TestFixture { check("void foo(unsigned int x, bool y) {\n" " if (0 > x || y) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check("void foo(int x, bool y) {\n" " if (0 > x || y) {}\n" @@ -8792,7 +8793,7 @@ class TestOther : public TestFixture { check("void foo(unsigned int x, bool y) {\n" " if (x >= 0 || y) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\n", errout_str()); check("void foo(int x, bool y) {\n" " if (x >= 0 || y) {}\n" @@ -8815,7 +8816,7 @@ class TestOther : public TestFixture { check("template void foo(unsigned int x) {\n" "if (x <= 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); } // #8836 @@ -8826,7 +8827,7 @@ class TestOther : public TestFixture { " value = 0u;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Checking if unsigned expression 'value' is less than zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\n", errout_str()); // #9040 /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build(); @@ -8843,7 +8844,7 @@ class TestOther : public TestFixture { " constexpr const auto y = 0xFFFFU;\n" " if (y < x) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Checking if unsigned expression 'y' is less than zero.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\n", errout_str()); // #12387 check("template\n" @@ -8869,7 +8870,7 @@ class TestOther : public TestFixture { check("void foo(const int* x) {\n" " if (x >= 0) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\n", errout_str()); { const char code[] = "void foo(const int* x) {\n" @@ -8877,9 +8878,9 @@ class TestOther : public TestFixture { " if (x >= y) {}\n" "}"; check(code, true, false, true, false); - ASSERT_EQUALS("[test.cpp:3]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\n", errout_str()); check(code, true, false, true, true); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\n", errout_str()); } check("void foo(const int* x) {\n" " if (*x >= 0) {}\n" @@ -8889,7 +8890,7 @@ class TestOther : public TestFixture { check("void foo(const int* x) {\n" " if (x < 0) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) A pointer can not be negative so it is either pointless or an error to check if it is.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\n", errout_str()); { const char code[] = "void foo(const int* x) {\n" @@ -8898,9 +8899,9 @@ class TestOther : public TestFixture { "}"; check(code, true, false, true, false); - ASSERT_EQUALS("[test.cpp:3]: (style) A pointer can not be negative so it is either pointless or an error to check if it is.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\n", errout_str()); check(code, true, false, true, true); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) A pointer can not be negative so it is either pointless or an error to check if it is.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\n", errout_str()); } check("void foo(const int* x) {\n" @@ -8931,7 +8932,7 @@ class TestOther : public TestFixture { check("void foo(const Bar* x) {\n" " if (0 <= x) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\n", errout_str()); check("struct S {\n" " int* ptr;\n" @@ -8939,8 +8940,8 @@ class TestOther : public TestFixture { "void foo(S* first) {\n" " if (first.ptr >= 0) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not.\n" - "[test.cpp:4]: (style) Parameter 'first' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\n" + "[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("struct S {\n" @@ -8949,8 +8950,8 @@ class TestOther : public TestFixture { "void foo(S* first, S* second) {\n" " if((first.ptr - second.ptr) >= 0) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Parameter 'first' can be declared as pointer to const\n" - "[test.cpp:4]: (style) Parameter 'second' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("struct S {\n" @@ -8959,8 +8960,8 @@ class TestOther : public TestFixture { "void foo(S* first) {\n" " if((first.ptr) >= 0) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not.\n" - "[test.cpp:4]: (style) Parameter 'first' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\n" + "[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("struct S {\n" @@ -8969,8 +8970,8 @@ class TestOther : public TestFixture { "void foo(S* first, S* second) {\n" " if(0 <= first.ptr - second.ptr) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Parameter 'first' can be declared as pointer to const\n" - "[test.cpp:4]: (style) Parameter 'second' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("struct S {\n" @@ -8979,8 +8980,8 @@ class TestOther : public TestFixture { "void foo(S* first, S* second) {\n" " if(0 <= (first.ptr - second.ptr)) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Parameter 'first' can be declared as pointer to const\n" - "[test.cpp:4]: (style) Parameter 'second' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("struct S {\n" @@ -8989,8 +8990,8 @@ class TestOther : public TestFixture { "void foo(S* first, S* second) {\n" " if(first.ptr - second.ptr < 0) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Parameter 'first' can be declared as pointer to const\n" - "[test.cpp:4]: (style) Parameter 'second' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("struct S {\n" @@ -8999,8 +9000,8 @@ class TestOther : public TestFixture { "void foo(S* first, S* second) {\n" " if((first.ptr - second.ptr) < 0) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Parameter 'first' can be declared as pointer to const\n" - "[test.cpp:4]: (style) Parameter 'second' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("struct S {\n" @@ -9009,8 +9010,8 @@ class TestOther : public TestFixture { "void foo(S* first, S* second) {\n" " if(0 > first.ptr - second.ptr) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Parameter 'first' can be declared as pointer to const\n" - "[test.cpp:4]: (style) Parameter 'second' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("struct S {\n" @@ -9019,8 +9020,8 @@ class TestOther : public TestFixture { "void foo(S* first, S* second) {\n" " if(0 > (first.ptr - second.ptr)) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (style) Parameter 'first' can be declared as pointer to const\n" - "[test.cpp:4]: (style) Parameter 'second' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(const int* x) {\n" @@ -9031,24 +9032,24 @@ class TestOther : public TestFixture { check("void foo(Bar* x) {\n" " if (0 <= x.y) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'x' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(Bar* x) {\n" " if (0 <= x->y) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'x' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(Bar* x, Bar* y) {\n" " if (0 <= x->y - y->y ) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'x' can be declared as pointer to const\n" - "[test.cpp:1]: (style) Parameter 'y' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(const Bar* x) {\n" " if (0 > x) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) A pointer can not be negative so it is either pointless or an error to check if it is.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\n", errout_str()); check("void foo(const int* x) {\n" " if (0 > x[0]) {}\n" @@ -9058,12 +9059,12 @@ class TestOther : public TestFixture { check("void foo(Bar* x) {\n" " if (0 > x.y) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'x' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(Bar* x) {\n" " if (0 > x->y) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'x' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo() {\n" " int (*t)(void *a, void *b);\n" @@ -9081,23 +9082,23 @@ class TestOther : public TestFixture { "void packed_object_info(struct object_info *oi) {\n" " if (oi->typep < 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) A pointer can not be negative so it is either pointless or an error to check if it is.\n" - "[test.cpp:2]: (style) Parameter 'oi' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\n" + "[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("struct object_info { int typep[10]; };\n" "void packed_object_info(struct object_info *oi) {\n" " if (oi->typep < 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) A pointer can not be negative so it is either pointless or an error to check if it is.\n" - "[test.cpp:2]: (style) Parameter 'oi' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\n" + "[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("struct object_info { int *typep; };\n" "void packed_object_info(struct object_info *oi) {\n" " if (*oi->typep < 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'oi' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\n", errout_str()); } void checkSuspiciousSemicolon1() { @@ -9111,14 +9112,14 @@ class TestOther : public TestFixture { " for(int i = 0; i < 10; ++i); {\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious use of ; at the end of 'for' statement.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\n", errout_str()); check("void foo() {\n" " while (!quit); {\n" " do_something();\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious use of ; at the end of 'while' statement.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\n", errout_str()); } void checkSuspiciousSemicolon2() { @@ -9127,7 +9128,7 @@ class TestOther : public TestFixture { " do_something();\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious use of ; at the end of 'if' statement.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\n", errout_str()); // Seen this in the wild check("void foo() {\n" @@ -9175,7 +9176,7 @@ class TestOther : public TestFixture { checkP("void f(int a, int b) {\n" " a > b;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious operator '>', result is not used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\n", errout_str()); checkP("void f() {\n" // #10607 " for (auto p : m)\n" @@ -9189,34 +9190,34 @@ class TestOther : public TestFixture { " char *a; a = malloc(1024);\n" " free(a + 10);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\n", errout_str()); check("void foo(char *p) {\n" " char *a; a = malloc(1024);\n" " free(a - 10);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\n", errout_str()); check("void foo(char *p) {\n" " char *a; a = malloc(1024);\n" " free(10 + a);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\n", errout_str()); check("void foo(char *p) {\n" " char *a; a = new char[1024];\n" " delete[] (a + 10);\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const\n" - "[test.cpp:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset.\n", + ASSERT_EQUALS("[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\n", errout_str()); check("void foo(char *p) {\n" " char *a; a = new char;\n" " delete a + 10;\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const\n" - "[test.cpp:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset.\n", + ASSERT_EQUALS("[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\n", errout_str()); check("void foo(char *p) {\n" @@ -9233,7 +9234,7 @@ class TestOther : public TestFixture { " delete a + 10;\n" " delete b + 10;\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\n", errout_str()); check("void foo(char *p) {\n" " char *a; a = new char;\n" @@ -9249,8 +9250,8 @@ class TestOther : public TestFixture { " bar()\n" " delete a + 10;\n" "}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const\n" - "[test.cpp:4]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset.\n", + ASSERT_EQUALS("[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\n", errout_str()); check("void foo(size_t xx) {\n" @@ -9258,7 +9259,7 @@ class TestOther : public TestFixture { " ptr += xx;\n" " free(ptr + 1 - xx);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\n", errout_str()); check("void foo(size_t xx) {\n" " char *ptr; ptr = malloc(42);\n" @@ -9267,7 +9268,7 @@ class TestOther : public TestFixture { " free(otherPtr - xx - 1);\n" "}"); ASSERT_EQUALS( - "[test.cpp:2]: (style) Variable 'ptr' can be declared as pointer to const\n", + "[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\n", errout_str()); } @@ -9276,7 +9277,7 @@ class TestOther : public TestFixture { "void foo() {\n" " const std::string a = getA();\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\n", errout_str()); check("class A { public: A() {} char x[100]; };\n" "const A& getA(){static A a;return a;}\n" @@ -9285,7 +9286,7 @@ class TestOther : public TestFixture { " const A a = getA();\n" " return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\n", errout_str()); check("const int& getA(){static int a;return a;}\n" "int main()\n" @@ -9302,7 +9303,7 @@ class TestOther : public TestFixture { " const int a = getA + 3;\n" " return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:4]: (style) Local variable \'getA\' shadows outer function\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\n", errout_str()); check("class A { public: A() {} char x[100]; };\n" "const A& getA(){static A a;return a;}\n" @@ -9311,7 +9312,7 @@ class TestOther : public TestFixture { " const A a(getA());\n" " return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\n", errout_str()); check("const int& getA(){static int a;return a;}\n" "int main()\n" @@ -9441,7 +9442,7 @@ class TestOther : public TestFixture { " return s.empty();\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:8]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:21]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\n", errout_str()); check("struct C {\n" " const std::string & get() const { return m; }\n" @@ -9505,7 +9506,7 @@ class TestOther : public TestFixture { " if (c == m->get()) {}\n" "}\n"); TODO_ASSERT_EQUALS("", - "[test.cpp:16] -> [test.cpp:18]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value.\n", + "[test.cpp:16:33] -> [test.cpp:18:11]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("struct S {\n" // #12925 @@ -9520,8 +9521,8 @@ class TestOther : public TestFixture { " const std::string w(s->f());\n" " if (w.empty()) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying.\n" - "[test.cpp:10]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying.\n", + ASSERT_EQUALS("[test.cpp:6:23]: (performance, inconclusive) Use const reference for 'v' to avoid unnecessary data copying. [redundantCopyLocalConst]\n" + "[test.cpp:10:23]: (performance, inconclusive) Use const reference for 'w' to avoid unnecessary data copying. [redundantCopyLocalConst]\n", errout_str()); check("struct T {\n" @@ -9532,7 +9533,7 @@ class TestOther : public TestFixture { " const auto s = t.get();\n" " if (s.empty()) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\n", errout_str()); } void checkNegativeShift() { @@ -9541,25 +9542,25 @@ class TestOther : public TestFixture { " int a; a = 123;\n" " (void)(a << -1);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Shifting by a negative value is undefined behaviour\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\n", errout_str()); check("void foo()\n" "{\n" " int a; a = 123;\n" " (void)(a >> -1);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Shifting by a negative value is undefined behaviour\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\n", errout_str()); check("void foo()\n" "{\n" " int a; a = 123;\n" " a <<= -1;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Shifting by a negative value is undefined behaviour\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\n", errout_str()); check("void foo()\n" "{\n" " int a; a = 123;\n" " a >>= -1;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Shifting by a negative value is undefined behaviour\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\n", errout_str()); check("void foo()\n" "{\n" " std::cout << -1;\n" @@ -9578,14 +9579,14 @@ class TestOther : public TestFixture { check("void foo() {\n" " x = (-10+2) << 3;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (portability) Shifting a negative value is technically undefined behaviour\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\n", errout_str()); check("x = y ? z << $-1 : 0;"); ASSERT_EQUALS("", errout_str()); // Negative LHS check("const int x = -1 >> 2;"); - ASSERT_EQUALS("[test.cpp:1]: (portability) Shifting a negative value is technically undefined behaviour\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\n", errout_str()); // #6383 - unsigned type check("const int x = (unsigned int)(-1) >> 2;"); @@ -9596,10 +9597,10 @@ class TestOther : public TestFixture { "int shift2() { return 1 << -1 ;}\n" "int shift3() { return -1 >> 1 ;}\n" "int shift4() { return -1 << 1 ;}"); - ASSERT_EQUALS("[test.cpp:1]: (error) Shifting by a negative value is undefined behaviour\n" - "[test.cpp:2]: (error) Shifting by a negative value is undefined behaviour\n" - "[test.cpp:3]: (portability) Shifting a negative value is technically undefined behaviour\n" - "[test.cpp:4]: (portability) Shifting a negative value is technically undefined behaviour\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\n" + "[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\n" + "[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\n" + "[test.cpp:4:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\n", errout_str()); check("void f(int i) {\n" // #12916 " if (i < 0) {\n" @@ -9646,9 +9647,9 @@ class TestOther : public TestFixture { " memmove(a, b, 5);\n" "}"); ASSERT_EQUALS(// TODO "[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\n" - "[test.cpp:3]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'?\n" - "[test.cpp:4]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'?\n" - "[test.cpp:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'?\n", errout_str()); + "[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\n" + "[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\n" + "[test.cpp:5:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memmove()' with 'sizeof(*a)'? [incompleteArrayFill]\n", errout_str()); check("int a[5];\n" "namespace Z { struct B { int a[5]; } b; }\n" @@ -9656,22 +9657,22 @@ class TestOther : public TestFixture { " memset(::a, 123, 5);\n" " memset(Z::b.a, 123, 5);\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'?\n" + TODO_ASSERT_EQUALS("[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\n" "[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\n", - "[test.cpp:4]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'?\n", errout_str()); + "[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\n", errout_str()); check("void f() {\n" " Foo* a[5];\n" " memset(a, 'a', 5);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\n", errout_str()); check("class Foo {int a; int b;};\n" "void f() {\n" " Foo a[5];\n" " memset(a, 'a', 5);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\n", errout_str()); check("void f() {\n" " Foo a[5];\n" // Size of foo is unknown @@ -9695,14 +9696,14 @@ class TestOther : public TestFixture { " bool a[5];\n" " memset(a, false, 5);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\n", errout_str()); check("void f() {\n" " const int n = 5;" " int a[n];\n" " memset(a, 0, n);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\n", errout_str()); } void redundantVarAssignment() { @@ -10191,7 +10192,7 @@ class TestOther : public TestFixture { " a = p;\n" "}"); ASSERT_EQUALS( - "[test.cpp:2]: (style) Variable 'a' can be declared as pointer to const\n", + "[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\n", errout_str()); check("void f() {\n" @@ -10200,7 +10201,7 @@ class TestOther : public TestFixture { " a = p;\n" "}"); ASSERT_EQUALS( - "[test.cpp:2]: (style) Variable 'a' can be declared as pointer to const\n", + "[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\n", errout_str()); } @@ -10214,7 +10215,7 @@ class TestOther : public TestFixture { " x.a = _mm_set1_ps(1.0);\n" " x.a = _mm_set1_ps(2.0);\n" "}"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:8]: (style) Variable 'x.a' is reassigned a value before the old one has been used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\n", errout_str()); check("void f() {\n" " struct AB ab;\n" @@ -10222,7 +10223,7 @@ class TestOther : public TestFixture { " ab.y = 41;\n" " ab.x = 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style) Variable 'ab.x' is reassigned a value before the old one has been used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\n", errout_str()); check("void f() {\n" " struct AB ab = {0};\n" @@ -10267,7 +10268,7 @@ class TestOther : public TestFixture { " u.l1 = 1;\n" " u.l1 = 2;\n" "}", true, false, false); - ASSERT_EQUALS("[test.cpp:13] -> [test.cpp:14]: (style) Variable 'u.l1' is reassigned a value before the old one has been used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\n", errout_str()); // Ticket #10093 "redundantAssignment when using a union" check("typedef union fixed32_union {\n" @@ -10364,7 +10365,7 @@ class TestOther : public TestFixture { " aSrcBuf.mnBitCount = nDestBits;\n" " bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\n" "}", false); - ASSERT_EQUALS("[test.c:3] -> [test.c:5]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used.\n", errout_str()); + ASSERT_EQUALS("[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\n", errout_str()); check("void ConvertBitmapData(sal_uInt16 nDestBits) {\n" " BitmapBuffer aSrcBuf;\n" " aSrcBuf.mnBitCount = nSrcBits;\n" @@ -10372,7 +10373,7 @@ class TestOther : public TestFixture { " aSrcBuf.mnBitCount = nDestBits;\n" " bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used.\n", + ASSERT_EQUALS("[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\n", errout_str()); check("class C { void operator=(int x); };\n" // #8368 - assignment operator might have side effects => inconclusive @@ -10381,7 +10382,7 @@ class TestOther : public TestFixture { " c = x;\n" " c = x;\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\n", errout_str()); } void redundantVarAssignment_stackoverflow() { @@ -10465,7 +10466,7 @@ class TestOther : public TestFixture { " }\n" " ret = 3;\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:8]: (style) Variable 'ret' is reassigned a value before the old one has been used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\n", errout_str()); } void redundantVarAssignment_pointer() { @@ -10534,7 +10535,7 @@ class TestOther : public TestFixture { " break;\n" " }" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:7]: (style) Variable 'ret' is reassigned a value before the old one has been used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\n", errout_str()); } void redundantInitialization() { @@ -10742,7 +10743,7 @@ class TestOther : public TestFixture { " a = b;\n" " return a * b * c;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style) Variable 'a' is assigned an expression that holds the same value.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:5:5]: (style) Variable 'a' is assigned an expression that holds the same value. [redundantAssignment]\n", errout_str()); check("int main() {\n" " int a = 0;\n" @@ -10760,7 +10761,7 @@ class TestOther : public TestFixture { " a = b = 5;\n" " return a * b * c;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:5:11]: (style) Redundant initialization for 'b'. The initialized value is overwritten before it is read. [redundantInitialization]\n", errout_str()); check("int f(int i) {\n" // #12874 " int j = i + 1;\n" @@ -10791,7 +10792,7 @@ class TestOther : public TestFixture { void varFuncNullUB() { // #4482 check("void a(...);\n" "void b() { a(NULL); }"); - ASSERT_EQUALS("[test.cpp:2]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\n", errout_str()); check("void a(char *p, ...);\n" "void b() { a(NULL, 2); }"); @@ -10809,7 +10810,7 @@ class TestOther : public TestFixture { " c = getchar();\n" " } ;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Storing getchar() return value in char variable and then comparing with EOF.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\n", errout_str()); check("void f() {\n" "unsigned char c = getchar();\n" @@ -10818,7 +10819,7 @@ class TestOther : public TestFixture { " bar(c);\n" " } ;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Storing getchar() return value in char variable and then comparing with EOF.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\n", errout_str()); check("void f() {\n" " unsigned char c; c = getchar();\n" @@ -10828,7 +10829,7 @@ class TestOther : public TestFixture { " c = getchar();\n" " } ;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Storing getchar() return value in char variable and then comparing with EOF.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\n", errout_str()); check("void f() {\n" " unsigned char c;\n" @@ -10836,7 +10837,7 @@ class TestOther : public TestFixture { " {\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Storing getchar() return value in char variable and then comparing with EOF.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\n", errout_str()); check("void f() {\n" " int i; i = getchar();\n" @@ -10866,7 +10867,7 @@ class TestOther : public TestFixture { " c = getc (pFile);\n" "} while (c != EOF);" "}"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Storing getc() return value in char variable and then comparing with EOF.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\n", errout_str()); check("void f (FILE * pFile){\n" "unsigned char c;\n" @@ -10874,7 +10875,7 @@ class TestOther : public TestFixture { " c = getc (pFile);\n" "} while (EOF != c);" "}"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Storing getc() return value in char variable and then comparing with EOF.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\n", errout_str()); check("void f (FILE * pFile){\n" "int i;\n" @@ -10900,7 +10901,7 @@ class TestOther : public TestFixture { " c = fgetc (pFile);\n" "} while (c != EOF);" "}"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Storing fgetc() return value in char variable and then comparing with EOF.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\n", errout_str()); check("void f (FILE * pFile){\n" "char c;\n" @@ -10908,7 +10909,7 @@ class TestOther : public TestFixture { " c = fgetc (pFile);\n" "} while (EOF != c);" "}"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Storing fgetc() return value in char variable and then comparing with EOF.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\n", errout_str()); check("void f (FILE * pFile){\n" "signed char c;\n" @@ -10942,7 +10943,7 @@ class TestOther : public TestFixture { " ch = std::cin.get();\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Storing cin.get() return value in char variable and then comparing with EOF.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\n", errout_str()); check("void f(){\n" " char ch; ch = std::cin.get();\n" @@ -10951,7 +10952,7 @@ class TestOther : public TestFixture { " ch = std::cin.get();\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Storing cin.get() return value in char variable and then comparing with EOF.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\n", errout_str()); check("void f(){\n" " int i; i = std::cin.get();\n" @@ -11071,7 +11072,7 @@ class TestOther : public TestFixture { " A a;" " A a2;" "};", true, false, true); - ASSERT_EQUALS("[test.cpp:8]: (performance) Function parameter 'a2' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\n", errout_str()); check("struct A\n" "{\n" @@ -11085,7 +11086,7 @@ class TestOther : public TestFixture { " A a;" " A a2;" "};", true, false, true); - ASSERT_EQUALS("[test.cpp:8]: (performance) Function parameter 'a2' should be passed by const reference.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\n", errout_str()); check("std::map m;\n" // #10817 "void f(const decltype(m)::const_iterator i) {}"); @@ -11098,7 +11099,7 @@ class TestOther : public TestFixture { "void g() {\n" " pf = f;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:2]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function.\n", + ASSERT_EQUALS("[test.cpp:6:10] -> [test.cpp:2:24]: (performance) Function parameter 'v' should be passed by const reference. However it seems that 'f' is a callback function. [passedByValueCallback]\n", errout_str()); check("template struct A;\n" // #12621 @@ -11127,27 +11128,27 @@ class TestOther : public TestFixture { check("bool f(int x){\n" " return isless(x,x);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\n", errout_str()); check("bool f(int x){\n" " return isgreater(x,x);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\n", errout_str()); check("bool f(int x){\n" " return islessgreater(x,x);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\n", errout_str()); check("bool f(int x){\n" " return islessequal(x,x);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\n", errout_str()); check("bool f(int x){\n" " return isgreaterequal(x,x);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\n", errout_str()); // no warning should be reported for check("bool f(int x, int y){\n" @@ -11168,12 +11169,12 @@ class TestOther : public TestFixture { check("int *f(int *x) {\n" " return &*x;\n" "}\n", true, true); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant pointer operation on 'x' - it's already a pointer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\n", errout_str()); check("int *f(int *y) {\n" " return &(*y);\n" "}\n", true, true); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant pointer operation on 'y' - it's already a pointer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\n", errout_str()); check("int f() {\n" // #10991 " int value = 4;\n" @@ -11181,14 +11182,14 @@ class TestOther : public TestFixture { " int result2 = *&value;\n" " return result1 + result2;\n" "}\n", true, true); - ASSERT_EQUALS("[test.cpp:3]: (style) Redundant pointer operation on 'value' - it's already a variable.\n" - "[test.cpp:4]: (style) Redundant pointer operation on 'value' - it's already a variable.\n", + ASSERT_EQUALS("[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\n" + "[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\n", errout_str()); check("void f(int& a, int b) {\n" " *(&a) = b;\n" "}\n", true, true); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant pointer operation on 'a' - it's already a variable.\n", + ASSERT_EQUALS("[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\n", errout_str()); check("void f(int**& p) {}\n", true, true); @@ -11222,20 +11223,20 @@ class TestOther : public TestFixture { check("void f(char **ptr) {\n" " int *x = &(*ptr)[10];\n" "}\n", true, true); - ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'x' can be declared as pointer to const\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\n", errout_str()); // function calls check("void f(Mutex *mut) {\n" " pthread_mutex_lock(&*mut);\n" "}\n", true, false); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant pointer operation on 'mut' - it's already a pointer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\n", errout_str()); // make sure we got the AST match for "(" right check("void f(char *ptr) {\n" " if (&*ptr == NULL)\n" " return;\n" "}\n", true, true); - ASSERT_EQUALS("[test.cpp:2]: (style) Redundant pointer operation on 'ptr' - it's already a pointer.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\n", errout_str()); // no warning for macros checkP("#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\n" @@ -11274,7 +11275,7 @@ class TestOther : public TestFixture { " return;\n" " destroy();\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("void f() {\n" " int counter = 0;\n" @@ -11282,7 +11283,7 @@ class TestOther : public TestFixture { " if (!counter)\n" " destroy();\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("void f() {\n" " int counter = 0;\n" @@ -11291,7 +11292,7 @@ class TestOther : public TestFixture { " return;\n" " destroy();\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("void f() {\n" " int counter = 0;\n" @@ -11300,7 +11301,7 @@ class TestOther : public TestFixture { " return;\n" " destroy();\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("void f() {\n" " int counter = 0;\n" @@ -11308,7 +11309,7 @@ class TestOther : public TestFixture { " if (counter == 0)\n" " destroy();\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("void f() {\n" " int counter = 0;\n" @@ -11316,7 +11317,7 @@ class TestOther : public TestFixture { " if (0 == counter)\n" " destroy();\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("void f() {\n" " int counter = 0;\n" @@ -11325,7 +11326,7 @@ class TestOther : public TestFixture { " return;\n" " destroy()\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("void f() {\n" " int counter = 0;\n" @@ -11334,7 +11335,7 @@ class TestOther : public TestFixture { " return;\n" " destroy()\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("void f() {\n" " int counter = 0;\n" @@ -11342,7 +11343,7 @@ class TestOther : public TestFixture { " if (counter <= 0)\n" " destroy();\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("void f() {\n" " int counter = 0;\n" @@ -11350,7 +11351,7 @@ class TestOther : public TestFixture { " if (0 >= counter)\n" " destroy();\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("void f() {\n" " int counter = 0;\n" @@ -11446,7 +11447,7 @@ class TestOther : public TestFixture { " return counter;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("int f() {\n" " int counter = 0;\n" @@ -11457,7 +11458,7 @@ class TestOther : public TestFixture { " return counter;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("int f() {\n" @@ -11468,7 +11469,7 @@ class TestOther : public TestFixture { " }\n" " return counter;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("int f() {\n" " int counter = 0;\n" @@ -11478,7 +11479,7 @@ class TestOther : public TestFixture { " }\n" " return counter;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("int f() {\n" " int counter = 0;\n" @@ -11489,7 +11490,7 @@ class TestOther : public TestFixture { " return counter;\n" " \n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("int f() {\n" " int counter = 0;\n" @@ -11500,14 +11501,14 @@ class TestOther : public TestFixture { " return counter;\n" " \n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); } void testUnusedLabel() { check("void f() {\n" " label:\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Label 'label' is not used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\n", errout_str()); check("void f() {\n" " label:\n" @@ -11524,7 +11525,7 @@ class TestOther : public TestFixture { "void g() {\n" " label:\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (style) Label 'label' is not used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\n", errout_str()); check("void f() {\n" " switch(a) {\n" @@ -11557,8 +11558,8 @@ class TestOther : public TestFixture { " return 2;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()?\n" - "[test.cpp:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\n" + "[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\n", errout_str()); check("int test(char art) {\n" " switch (art) {\n" @@ -11567,7 +11568,7 @@ class TestOther : public TestFixture { " }\n" " label:\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (style) Label 'label' is not used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\n", errout_str()); } #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__) @@ -11597,7 +11598,7 @@ class TestOther : public TestFixture { " int x = dostuff();\n" " return x + x++;\n" "}", false); - ASSERT_EQUALS("[test.c:3]: (error) Expression 'x+x++' depends on order of evaluation of side effects\n", errout_str()); + ASSERT_EQUALS("[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); // #7226 check("long int f1(const char *exp) {\n" @@ -11608,7 +11609,7 @@ class TestOther : public TestFixture { check("long int f1(const char *exp) {\n" " return dostuff(++exp, exp, 10);\n" "}", false); - ASSERT_EQUALS("[test.c:2]: (error) Expression '++exp,exp' depends on order of evaluation of side effects\n", errout_str()); + ASSERT_EQUALS("[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); check("void f() {\n" " int a;\n" @@ -11634,30 +11635,30 @@ class TestOther : public TestFixture { " int a[10];\n" " a[x+y] = a[y+x]++;;\n" "}\n", false); - ASSERT_EQUALS("[test.c:3]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects\n", errout_str()); + ASSERT_EQUALS("[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); check("void f(int i) {\n" " int n = ++i + i;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Expression '++i+i' depends on order of evaluation of side effects\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); check("long int f1(const char *exp) {\n" " return dostuff(++exp, ++exp, 10);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17\n" - "[test.cpp:2]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\n" + "[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\n", errout_str()); check("void f(int i) {\n" " int n = (~(-(++i)) + i);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build(); checkCustomSettings("void f(int i) {\n" " i = i++ + 2;\n" "}", &settings11); - ASSERT_EQUALS("[test.cpp:2]: (error) Expression 'i+++2' depends on order of evaluation of side effects\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); } void testEvaluationOrderSelfAssignment() { @@ -11666,8 +11667,8 @@ class TestOther : public TestFixture { " int x = x = y + 1;\n" "}", false); ASSERT_EQUALS( - "[test.c:2]: (style) Redundant assignment of 'x' to itself.\n" - "[test.c:2]: (style) Redundant assignment of 'x' to itself.\n", // duplicate + "[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\n" + "[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\n", // duplicate errout_str()); } @@ -11677,7 +11678,7 @@ class TestOther : public TestFixture { "void f(int x) {\n" " return x + X++;\n" "}", dinit(CheckPOptions, $.cpp = false)); - ASSERT_EQUALS("[test.c:3]: (error) Expression 'x+x++' depends on order of evaluation of side effects\n", errout_str()); + ASSERT_EQUALS("[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); } void testEvaluationOrderSequencePointsFunctionCall() { @@ -11705,7 +11706,7 @@ class TestOther : public TestFixture { " int t;\n" " dostuff(t=1,t^c);\n" "}", false); - ASSERT_EQUALS("[test.c:3]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects\n", errout_str()); + ASSERT_EQUALS("[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); check("void f(void) {\n" " int t;\n" @@ -11733,7 +11734,7 @@ class TestOther : public TestFixture { " ;\n" " while (f(++fp, (*fp) <= 7));\n" "}\n", false); - ASSERT_EQUALS("[test.c:4]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects\n", errout_str()); + ASSERT_EQUALS("[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); } void testEvaluationOrderSizeof() { @@ -11759,8 +11760,8 @@ class TestOther : public TestFixture { " return;\n" " }\n" "}", false); - ASSERT_EQUALS("[test.c:8]: (style) Checking if unsigned expression 'd.n' is less than zero.\n" - "[test.c:12]: (style) Checking if unsigned expression 'd.n' is less than zero.\n", + ASSERT_EQUALS("[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\n" + "[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\n", errout_str()); } @@ -11771,7 +11772,7 @@ class TestOther : public TestFixture { " g(std::move(a));\n" " g(std::move(a));\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Access of moved variable 'a'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\n", errout_str()); } void doubleMoveMemberInitialization1() { @@ -11785,7 +11786,7 @@ class TestOther : public TestFixture { " B b1;\n" " B b2;\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (warning) Access of moved variable 'b'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\n", errout_str()); } void doubleMoveMemberInitialization2() { @@ -11798,7 +11799,7 @@ class TestOther : public TestFixture { " B b1;\n" " B b2;\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Access of moved variable 'b'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\n", errout_str()); } void doubleMoveMemberInitialization3() { // #9974 @@ -11819,7 +11820,7 @@ class TestOther : public TestFixture { " int c;\n" " S d;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Access of moved variable 'd'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:51]: (warning, inconclusive) Access of moved variable 'd'. [accessMoved]\n", errout_str()); } void moveAndAssign1() { @@ -11839,7 +11840,7 @@ class TestOther : public TestFixture { " B b = g(std::move(a));\n" " C c = g(std::move(a));\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Access of moved variable 'a'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\n", errout_str()); } void moveAssignMoveAssign() { @@ -11855,8 +11856,8 @@ class TestOther : public TestFixture { " a = b;\n" " h(a);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Access of moved variable 'a'.\n" - "[test.cpp:8]: (warning) Access of moved variable 'a'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\n" + "[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\n", errout_str()); } void moveAndReset1() { @@ -11878,7 +11879,7 @@ class TestOther : public TestFixture { " b.reset(g(std::move(a)));\n" " c.reset(g(std::move(a)));\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (warning) Access of moved variable 'a'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\n", errout_str()); } void moveResetMoveReset() { @@ -11894,8 +11895,8 @@ class TestOther : public TestFixture { " a.reset(b);\n" " h(a);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Access of moved variable 'a'.\n" - "[test.cpp:8]: (warning) Access of moved variable 'a'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\n" + "[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\n", errout_str()); } void moveAndFunctionParameter() { @@ -11906,8 +11907,8 @@ class TestOther : public TestFixture { " g(a);\n" " A c = a;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Access of moved variable 'a'.\n" - "[test.cpp:6]: (warning) Access of moved variable 'a'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\n" + "[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\n", errout_str()); } void moveAndFunctionParameterReference() { @@ -11929,8 +11930,8 @@ class TestOther : public TestFixture { " g(a);\n" " A c = a;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Access of moved variable 'a'.\n" - "[test.cpp:6]: (warning) Access of moved variable 'a'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\n" + "[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\n", errout_str()); } void moveAndFunctionParameterUnknown() { @@ -11940,8 +11941,8 @@ class TestOther : public TestFixture { " g(a);\n" " A c = a;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) Access of moved variable 'a'.\n" - "[test.cpp:5]: (warning, inconclusive) Access of moved variable 'a'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\n" + "[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\n", errout_str()); } void moveAndReturn() { @@ -11953,7 +11954,7 @@ class TestOther : public TestFixture { " return g(std::move(b));\n" " return h(std::move(a),std::move(b));\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (warning) Access of moved variable 'a'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\n", errout_str()); } void moveAndClear() { @@ -11973,8 +11974,8 @@ class TestOther : public TestFixture { " x = p->x;\n" " y = p->y;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Access of moved variable 'p'.\n" - "[test.cpp:5]: (warning) Access of moved variable 'p'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\n" + "[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\n", errout_str()); } void moveAndAddressOf() { @@ -12012,7 +12013,7 @@ class TestOther : public TestFixture { " while(true)\n" " g(std::move(p));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Access of moved variable 'p'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:21]: (warning) Access of moved variable 'p'. [accessMoved]\n", errout_str()); check("std::list g(std::list&&);\n" "void f(std::listl) {\n" @@ -12020,8 +12021,8 @@ class TestOther : public TestFixture { " for (auto &j : g(std::move(l))) { (void)j; }\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'j' can be declared as reference to const\n" - "[test.cpp:4]: (warning) Access of moved variable 'l'.\n", + ASSERT_EQUALS("[test.cpp:4:20]: (style) Variable 'j' can be declared as reference to const [constVariableReference]\n" + "[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\n", errout_str()); } @@ -12032,7 +12033,7 @@ class TestOther : public TestFixture { " if(!f(std::move(callback)))\n" " callback();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Access of moved variable 'callback'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (warning) Access of moved variable 'callback'. [accessMoved]\n", errout_str()); } void moveClassVariable() @@ -12056,7 +12057,7 @@ class TestOther : public TestFixture { " g(std::forward(t));\n" " T s = t;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Access of forwarded variable 't'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\n", errout_str()); } void moveAndReference() { // #9791 @@ -12068,7 +12069,7 @@ class TestOther : public TestFixture { " g(std::move(s));\n" " h(r);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (warning) Access of moved variable 'r'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:7]: (warning) Access of moved variable 'r'. [accessMoved]\n", errout_str()); } void moveForRange() @@ -12120,7 +12121,7 @@ class TestOther : public TestFixture { " const std::string* s_p = &s;\n" " s_p->size();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Access of moved variable '.'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\n", errout_str()); } void funcArgNamesDifferent() { @@ -12138,15 +12139,15 @@ class TestOther : public TestFixture { "void Fred::func2(int A, int B, int C) { }\n" "void Fred::func3(int a, int b, int c) { }\n" "void Fred::func4(int A, int B, int C) { }"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'.\n" - "[test.cpp:3] -> [test.cpp:4]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'.\n" - "[test.cpp:3] -> [test.cpp:4]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'.\n" - "[test.cpp:7] -> [test.cpp:12]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'.\n" - "[test.cpp:7] -> [test.cpp:12]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'.\n" - "[test.cpp:7] -> [test.cpp:12]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'.\n" - "[test.cpp:9] -> [test.cpp:14]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'.\n" - "[test.cpp:9] -> [test.cpp:14]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'.\n" - "[test.cpp:9] -> [test.cpp:14]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\n" + "[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\n" + "[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\n" + "[test.cpp:7:20] -> [test.cpp:12:22]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\n" + "[test.cpp:7:27] -> [test.cpp:12:29]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\n" + "[test.cpp:7:34] -> [test.cpp:12:36]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\n" + "[test.cpp:9:20] -> [test.cpp:14:22]: (style, inconclusive) Function 'func4' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\n" + "[test.cpp:9:31] -> [test.cpp:14:29]: (style, inconclusive) Function 'func4' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\n" + "[test.cpp:9:42] -> [test.cpp:14:36]: (style, inconclusive) Function 'func4' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\n", errout_str()); } void funcArgOrderDifferent() { @@ -12167,11 +12168,11 @@ class TestOther : public TestFixture { "void Fred::func3(int c, int b, int a) { }\n" "void Fred::func4(int c, int b, int a) { }\n", true, false); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a'\n" - "[test.cpp:5] -> [test.cpp:6]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a'\n" - "[test.cpp:9] -> [test.cpp:14]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a'\n" - "[test.cpp:10] -> [test.cpp:15]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a'\n" - "[test.cpp:11] -> [test.cpp:16]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a'\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\n" + "[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\n" + "[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\n" + "[test.cpp:10:20] -> [test.cpp:15:22]: (warning) Function 'func3' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\n" + "[test.cpp:11:16] -> [test.cpp:16:22]: (warning) Function 'func4' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\n", errout_str()); } // #7846 - Syntax error when using C++11 braced-initializer in default argument @@ -12187,11 +12188,11 @@ class TestOther : public TestFixture { void shadowVariables() { check("int x;\n" "void f() { int x; }"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:2]: (style) Local variable \'x\' shadows outer variable\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\n", errout_str()); check("int x();\n" "void f() { int x; }"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:2]: (style) Local variable \'x\' shadows outer function\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\n", errout_str()); check("struct C {\n" " C(int x) : x(x) {}\n" // <- we do not want a FP here @@ -12217,7 +12218,7 @@ class TestOther : public TestFixture { ASSERT_EQUALS("", errout_str()); check("void f(int x) { int x; }"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (style) Local variable 'x' shadows outer argument\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\n", errout_str()); check("class C { C(); void foo() { static int C = 0; } }"); // #9195 - shadow constructor ASSERT_EQUALS("", errout_str()); @@ -12246,14 +12247,14 @@ class TestOther : public TestFixture { " int i{};\n" " void f() { int i; }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Local variable 'i' shadows outer variable\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:20]: (style) Local variable 'i' shadows outer variable [shadowVariable]\n", errout_str()); check("struct S {\n" " int i{};\n" " std::vector v;\n" " void f() const { for (const int& i : v) {} }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (style) Local variable 'i' shadows outer variable\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:4:38]: (style) Local variable 'i' shadows outer variable [shadowVariable]\n", errout_str()); check("struct S {\n" // #10405 " F* f{};\n" @@ -12263,7 +12264,7 @@ class TestOther : public TestFixture { "void S::f() const {\n" " for (const F& f : fl) {}\n" "};\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:7]: (style) Local variable 'f' shadows outer variable\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:8] -> [test.cpp:7:19]: (style) Local variable 'f' shadows outer variable [shadowVariable]\n", errout_str()); check("extern int a;\n" "int a;\n" @@ -12271,7 +12272,7 @@ class TestOther : public TestFixture { " int a;\n" " return 0;\n" "}\n", false); - ASSERT_EQUALS("[test.c:1] -> [test.c:4]: (style) Local variable 'a' shadows outer variable\n", errout_str()); + ASSERT_EQUALS("[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\n", errout_str()); check("int f() {\n" // #12591 " int g = 0;\n" @@ -12286,20 +12287,20 @@ class TestOther : public TestFixture { "void f(int x) {\n" " g((x & 0x01) >> 7);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\n", errout_str()); check("void g(int);\n" "void f(int x) {\n" " g((int)((x & 0x01) >> 7));\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\n", errout_str()); check("void g(int, int);\n" "void f(int x) {\n" " g(x, (x & 0x01) >> 7);\n" "}"); ASSERT_EQUALS( - "[test.cpp:3]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has.\n", + "[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\n", errout_str()); check("void g(int);\n" @@ -12379,7 +12380,7 @@ class TestOther : public TestFixture { " int x[] = { 10, 10 };\n" " f(x[0]);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'x' can be declared as const array\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\n", errout_str()); check("struct A { int x; };" "void g(int);\n" @@ -12472,8 +12473,8 @@ class TestOther : public TestFixture { " const int a[] = { i - 1 * i, 0 };\n" " auto s = S{ i - 1 * i };\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has.\n" - "[test.cpp:4]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has.\n", + ASSERT_EQUALS("[test.cpp:3:25]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has. [knownArgument]\n" + "[test.cpp:4:19]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has. [knownArgument]\n", errout_str()); checkP("#define MACRO(X) std::abs(X ? 0 : a)\n" @@ -12493,10 +12494,10 @@ class TestOther : public TestFixture { " dostuff(x * 0);\n" " dostuff(0 * x);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'.\n" - "[test.cpp:5]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'.\n" - "[test.cpp:6]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'.\n" - "[test.cpp:7]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (style) Argument 'false&&x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\n" + "[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\n" + "[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\n" + "[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\n", errout_str()); } void knownArgumentTernaryOperator() { // #10374 @@ -12522,7 +12523,7 @@ class TestOther : public TestFixture { " return diff;\n" "}"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:5] -> [test.cpp:5]: (error) Comparing pointers that point to different objects\n", + "[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\n", errout_str()); check("bool f() {\n" @@ -12533,9 +12534,9 @@ class TestOther : public TestFixture { " return xp > yp;\n" "}"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:4] -> [test.cpp:3] -> [test.cpp:5] -> [test.cpp:6]: (error) Comparing pointers that point to different objects\n" - "[test.cpp:4]: (style) Variable 'xp' can be declared as pointer to const\n" - "[test.cpp:5]: (style) Variable 'yp' can be declared as pointer to const\n", + "[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\n" + "[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\n" + "[test.cpp:5:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\n", errout_str()); check("bool f() {\n" @@ -12544,7 +12545,7 @@ class TestOther : public TestFixture { " return &x > &y;\n" "}"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:4] -> [test.cpp:3] -> [test.cpp:4] -> [test.cpp:4]: (error) Comparing pointers that point to different objects\n", + "[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\n", errout_str()); check("struct A {int data;};\n" @@ -12556,9 +12557,9 @@ class TestOther : public TestFixture { " return xp > yp;\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:5] -> [test.cpp:4] -> [test.cpp:6] -> [test.cpp:7]: (error) Comparing pointers that point to different objects\n" - "[test.cpp:5]: (style) Variable 'xp' can be declared as pointer to const\n" - "[test.cpp:6]: (style) Variable 'yp' can be declared as pointer to const\n", + "[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\n" + "[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\n" + "[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\n", errout_str()); check("struct A {int data;};\n" @@ -12570,16 +12571,16 @@ class TestOther : public TestFixture { " return xp > yp;\n" "}"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:3] -> [test.cpp:5] -> [test.cpp:2] -> [test.cpp:4] -> [test.cpp:6] -> [test.cpp:7]: (error) Comparing pointers that point to different objects\n" - "[test.cpp:5]: (style) Variable 'xp' can be declared as pointer to const\n" - "[test.cpp:6]: (style) Variable 'yp' can be declared as pointer to const\n", + "[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\n" + "[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\n" + "[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\n", errout_str()); check("bool f(int * xp, int* yp) {\n" " return &xp > &yp;\n" "}"); ASSERT_EQUALS( - "[test.cpp:1] -> [test.cpp:2] -> [test.cpp:1] -> [test.cpp:2] -> [test.cpp:2]: (error) Comparing pointers that point to different objects\n", + "[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\n", errout_str()); check("int f() {\n" @@ -12588,7 +12589,7 @@ class TestOther : public TestFixture { " return &x - &y;\n" "}"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:4] -> [test.cpp:3] -> [test.cpp:4] -> [test.cpp:4]: (error) Subtracting pointers that point to different objects\n", + "[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\n", errout_str()); check("bool f() {\n" @@ -12597,8 +12598,8 @@ class TestOther : public TestFixture { " int* yp = &x[1];\n" " return xp > yp;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'xp' can be declared as pointer to const\n" - "[test.cpp:4]: (style) Variable 'yp' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\n" + "[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\n", errout_str()); check("bool f(const int * xp, const int* yp) {\n" @@ -12629,21 +12630,21 @@ class TestOther : public TestFixture { " int* yp = &y->data;\n" " return xp > yp;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'xp' can be declared as pointer to const\n" - "[test.cpp:6]: (style) Variable 'yp' can be declared as pointer to const\n", + ASSERT_EQUALS("[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\n" + "[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\n", errout_str()); check("struct S { int i; };\n" // #11576 "int f(S s) {\n" " return &s.i - (int*)&s;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) C-style pointer casting\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); check("struct S { int i; };\n" "int f(S s1, S s2) {\n" " return &s1.i - reinterpret_cast(&s2);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:3] -> [test.cpp:3]: (error) Subtracting pointers that point to different objects\n", + ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:12] -> [test.cpp:2:15] -> [test.cpp:3:43] -> [test.cpp:3:18]: (error) Subtracting pointers that point to different objects [subtractPointers]\n", errout_str()); check("struct S { int a; int b; };\n" // #12422 @@ -12687,7 +12688,7 @@ class TestOther : public TestFixture { check("void f(unsigned int x) {\n" " int y = x % 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Modulo of one is always equal to zero\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\n", errout_str()); check("void f() {\n" " for (int x = 1; x < 10; x++) {\n" @@ -12720,7 +12721,7 @@ class TestOther : public TestFixture { " u.i = 0;\n" " u.i = u.f;\n" // <- error "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Overlapping read/write of union is undefined behavior\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\n", errout_str()); check("void foo() {\n" // #11013 " union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\n" @@ -12733,19 +12734,19 @@ class TestOther : public TestFixture { " char a[10];\n" " memcpy(&a[5], &a[4], 2u);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Overlapping read/write in memcpy() is undefined behavior\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\n", errout_str()); check("void foo() {\n" " char a[10];\n" " memcpy(a+5, a+4, 2u);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Overlapping read/write in memcpy() is undefined behavior\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\n", errout_str()); check("void foo() {\n" " char a[10];\n" " memcpy(a, a+1, 2u);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Overlapping read/write in memcpy() is undefined behavior\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\n", errout_str()); check("void foo() {\n" " char a[8];\n" @@ -12757,7 +12758,7 @@ class TestOther : public TestFixture { "void foo() {\n" " memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Overlapping read/write in memcpy() is undefined behavior\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\n", errout_str()); check("int K[2];\n" // #12638 "void f(int* p) {\n" @@ -12775,10 +12776,10 @@ class TestOther : public TestFixture { " memcpy(p, p + 1, 2 * sizeof(*p));\n" " memcpy(p + 1, p, 2 * sizeof(*p));\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Overlapping read/write in memcpy() is undefined behavior\n" - "[test.cpp:4]: (error) Overlapping read/write in memcpy() is undefined behavior\n" - "[test.cpp:5]: (error) Overlapping read/write in memcpy() is undefined behavior\n" - "[test.cpp:6]: (error) Overlapping read/write in memcpy() is undefined behavior\n", + ASSERT_EQUALS("[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\n" + "[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\n" + "[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\n" + "[test.cpp:6:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\n", errout_str()); // wmemcpy @@ -12786,25 +12787,25 @@ class TestOther : public TestFixture { " wchar_t a[10];\n" " wmemcpy(&a[5], &a[4], 2u);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Overlapping read/write in wmemcpy() is undefined behavior\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\n", errout_str()); check("void foo() {\n" " wchar_t a[10];\n" " wmemcpy(a+5, a+4, 2u);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Overlapping read/write in wmemcpy() is undefined behavior\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\n", errout_str()); check("void foo() {\n" " wchar_t a[10];\n" " wmemcpy(a, a+1, 2u);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Overlapping read/write in wmemcpy() is undefined behavior\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\n", errout_str()); // strcpy check("void foo(char *ptr) {\n" " strcpy(ptr, ptr);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Overlapping read/write in strcpy() is undefined behavior\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\n", errout_str()); } void constVariableArrayMember() { // #10371 @@ -12826,8 +12827,8 @@ class TestOther : public TestFixture { " g(p);\n" " g(&i);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (style) Pointer expression 'p' converted to bool is always true.\n" - "[test.cpp:6]: (style) Pointer expression '&i' converted to bool is always true.\n", + ASSERT_EQUALS("[test.cpp:5:7]: (style) Pointer expression 'p' converted to bool is always true. [knownPointerToBool]\n" + "[test.cpp:6:7]: (style) Pointer expression '&i' converted to bool is always true. [knownPointerToBool]\n", errout_str()); check("void f() {\n" @@ -12858,7 +12859,7 @@ class TestOther : public TestFixture { " }\n" " return false;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Pointer expression 'a.x' converted to bool is always true.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\n", errout_str()); check("void f(bool* b) { if (b) *b = true; }"); ASSERT_EQUALS("", errout_str()); @@ -12867,27 +12868,27 @@ class TestOther : public TestFixture { " int* x = nullptr;\n" " return bool(x);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Pointer expression 'x' converted to bool is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\n", errout_str()); check("bool f() {\n" " int* x = nullptr;\n" " return bool{x};\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Pointer expression 'x' converted to bool is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\n", errout_str()); check("struct A { A(bool); };\n" "A f() {\n" " int* x = nullptr;\n" " return A(x);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Pointer expression 'x' converted to bool is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\n", errout_str()); check("struct A { A(bool); };\n" "A f() {\n" " int* x = nullptr;\n" " return A{x};\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Pointer expression 'x' converted to bool is always false.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14]: (style) Pointer expression 'x' converted to bool is always false. [knownPointerToBool]\n", errout_str()); check("struct B { virtual void f() {} };\n" // #11929 "struct D : B {};\n" @@ -12918,7 +12919,7 @@ class TestOther : public TestFixture { " for (auto s : ss)\n" " (void)s.size();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (performance) Range variable 's' should be declared as const reference.\n", + ASSERT_EQUALS("[test.cpp:3:15]: (performance) Range variable 's' should be declared as const reference. [iterateByValue]\n", errout_str()); } @@ -12929,7 +12930,7 @@ class TestOther : public TestFixture { " if (f > 1.0) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1.0' is always false.\n", + "[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.0' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #13508 @@ -12946,7 +12947,7 @@ class TestOther : public TestFixture { " if (f > +1.0) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > +1.0' is always false.\n", + "[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > +1.0' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" @@ -12954,7 +12955,7 @@ class TestOther : public TestFixture { " if (f < +1.0) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f < 1.0' is always false.\n", + "[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f < 1.0' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #11200 @@ -12962,7 +12963,7 @@ class TestOther : public TestFixture { " if (pf > 1.0) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > 1.0' is always false.\n", + "[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > 1.0' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #13508 @@ -12979,7 +12980,7 @@ class TestOther : public TestFixture { " if (pf > +1.0) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > +1.0' is always false.\n", + "[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf > +1.0' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" @@ -12987,7 +12988,7 @@ class TestOther : public TestFixture { " if (pf < +1.0) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf < 1.0' is always false.\n", + "[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'pf < 1.0' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #11200 @@ -12995,7 +12996,7 @@ class TestOther : public TestFixture { " if (nf > -1.0) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'nf > -1.0' is always false.\n", + "[test.cpp:2:18] -> [test.cpp:3:12]: (style) The comparison 'nf > -1.0' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #13508 @@ -13021,7 +13022,7 @@ class TestOther : public TestFixture { " if (f > 1.00f) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1.00f' is always false.\n", + "[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00f' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #13508 @@ -13038,7 +13039,7 @@ class TestOther : public TestFixture { " if (f > 1.00) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > 1.00' is always false.\n", + "[test.cpp:2:16] -> [test.cpp:3:11]: (style) The comparison 'f > 1.00' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #13508 @@ -13058,7 +13059,7 @@ class TestOther : public TestFixture { " if (i < +1) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'i < 1' is always false.\n", + "[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i < 1' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" // #13506 @@ -13066,7 +13067,7 @@ class TestOther : public TestFixture { " if (i > +1) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'i > +1' is always false.\n", + "[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'i > +1' is always false. [knownConditionTrueFalse]\n", errout_str()); } };