unittests: removed not needed '\n' at the end of testcases.
This commit is contained in:
parent
a08083a342
commit
1b9c1c03fa
|
@ -577,7 +577,7 @@ private:
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" A & operator=(const A &);\n"
|
" A & operator=(const A &);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A & A::operator=(const A &a) { return *this; }\n");
|
"A & A::operator=(const A &a) { return *this; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
|
@ -586,7 +586,7 @@ private:
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" A & operator=(const A &a);\n"
|
" A & operator=(const A &a);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A & A::operator=(const A &a) { return *this; }\n");
|
"A & A::operator=(const A &a) { return *this; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
|
@ -595,7 +595,7 @@ private:
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" A & operator=(const A &);\n"
|
" A & operator=(const A &);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A & A::operator=(const A &a) { return a; }\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]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
|
@ -604,7 +604,7 @@ private:
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" A & operator=(const A &a);\n"
|
" A & operator=(const A &a);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A & A::operator=(const A &a) { return a; }\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]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
|
@ -641,7 +641,7 @@ private:
|
||||||
" B & operator=(const B &);\n"
|
" B & operator=(const B &);\n"
|
||||||
" };\n"
|
" };\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::B & A::B::operator=(const A::B &b) { return *this; }\n");
|
"A::B & A::B::operator=(const A::B &b) { return *this; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
|
@ -654,7 +654,7 @@ private:
|
||||||
" B & operator=(const B &);\n"
|
" B & operator=(const B &);\n"
|
||||||
" };\n"
|
" };\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::B & A::B::operator=(const A::B &b) { return b; }\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]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -847,7 +847,7 @@ private:
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" A & operator=(const A &);\n"
|
" A & operator=(const A &);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A & A::operator=(const A &a) { if (&a != this) { } return *this; }\n");
|
"A & A::operator=(const A &a) { if (&a != this) { } return *this; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// this test doesn't have an assignment test but doesn't need it
|
// this test doesn't have an assignment test but doesn't need it
|
||||||
|
@ -857,7 +857,7 @@ private:
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" A & operator=(const A &);\n"
|
" A & operator=(const A &);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A & A::operator=(const A &a) { return *this; }\n");
|
"A & A::operator=(const A &a) { return *this; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// this test needs an assignment test and has it
|
// this test needs an assignment test and has it
|
||||||
|
@ -992,7 +992,7 @@ private:
|
||||||
" B & operator=(const B &);\n"
|
" B & operator=(const B &);\n"
|
||||||
" };\n"
|
" };\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }\n");
|
"A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// this test doesn't have an assignment test but doesn't need it
|
// this test doesn't have an assignment test but doesn't need it
|
||||||
|
@ -1006,7 +1006,7 @@ private:
|
||||||
" B & operator=(const B &);\n"
|
" B & operator=(const B &);\n"
|
||||||
" };\n"
|
" };\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::B & A::B::operator=(const A::B &b) { return *this; }\n");
|
"A::B & A::B::operator=(const A::B &b) { return *this; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// this test needs an assignment test and has it
|
// this test needs an assignment test and has it
|
||||||
|
@ -1029,7 +1029,7 @@ private:
|
||||||
" s = strdup(b.s);\n"
|
" s = strdup(b.s);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" return *this;\n"
|
" return *this;\n"
|
||||||
" }\n");
|
" }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// this test needs an assignment test but doesn't have it
|
// this test needs an assignment test but doesn't have it
|
||||||
|
@ -1049,7 +1049,7 @@ private:
|
||||||
" free(s);\n"
|
" free(s);\n"
|
||||||
" s = strdup(b.s);\n"
|
" s = strdup(b.s);\n"
|
||||||
" return *this;\n"
|
" return *this;\n"
|
||||||
" }\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]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1085,7 +1085,7 @@ private:
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" A & operator=(const A &);\n"
|
" A & operator=(const A &);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A & A::operator=(const A &a) { return *this; }\n");
|
"A & A::operator=(const A &a) { return *this; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it
|
// this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it
|
||||||
|
@ -1149,7 +1149,7 @@ private:
|
||||||
" B & operator=(const B &);\n"
|
" B & operator=(const B &);\n"
|
||||||
" };\n"
|
" };\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::B & A::B::operator=(const A::B &b) { return *this; }\n");
|
"A::B & A::B::operator=(const A::B &b) { return *this; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it
|
// this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it
|
||||||
|
@ -1882,7 +1882,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"\n"
|
"\n"
|
||||||
"void Fred::foobar()\n"
|
"void Fred::foobar()\n"
|
||||||
"{ }\n");
|
"{ }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2870,7 +2870,7 @@ private:
|
||||||
" };\n"
|
" };\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"int Fred::B::A::getA() { return a; }\n"
|
"int Fred::B::A::getA() { return a; }\n"
|
||||||
"int Fred::B::getB() { return b; }\n");
|
"int Fred::B::getB() { return b; }");
|
||||||
ASSERT_EQUALS("[test.cpp:12] -> [test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const.\n"
|
ASSERT_EQUALS("[test.cpp:12] -> [test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const.\n"
|
||||||
"[test.cpp:11] -> [test.cpp:7]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const.\n" , errout.str());
|
"[test.cpp:11] -> [test.cpp:7]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const.\n" , errout.str());
|
||||||
}
|
}
|
||||||
|
@ -4023,7 +4023,7 @@ private:
|
||||||
" int var;\n"
|
" int var;\n"
|
||||||
" };\n"
|
" };\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"int N::Base::getResourceName() { return var; }\n");
|
"int N::Base::getResourceName() { return var; }");
|
||||||
ASSERT_EQUALS("[test.cpp:10] -> [test.cpp:6]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:10] -> [test.cpp:6]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const.\n", errout.str());
|
||||||
|
|
||||||
checkConst("namespace N\n"
|
checkConst("namespace N\n"
|
||||||
|
@ -4051,7 +4051,7 @@ private:
|
||||||
" };\n"
|
" };\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"using namespace N;\n"
|
"using namespace N;\n"
|
||||||
"int Base::getResourceName() { return var; }\n");
|
"int Base::getResourceName() { return var; }");
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:6]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const.\n",
|
TODO_ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:6]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const.\n",
|
||||||
"", errout.str());
|
"", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -5191,7 +5191,7 @@ private:
|
||||||
" B() : b(0) { }\n"
|
" B() : b(0) { }\n"
|
||||||
" int func();\n"
|
" int func();\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"int B::func() { return b; }\n");
|
"int B::func() { return b; }");
|
||||||
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:6]: (style, inconclusive) Technically the member function 'B::func' can be const.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:6]: (style, inconclusive) Technically the member function 'B::func' can be const.\n", errout.str());
|
||||||
|
|
||||||
// base class has no virtual function
|
// base class has no virtual function
|
||||||
|
@ -5217,7 +5217,7 @@ private:
|
||||||
" B() : b(0) { }\n"
|
" B() : b(0) { }\n"
|
||||||
" int func();\n"
|
" int func();\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"int B::func() { return b; }\n");
|
"int B::func() { return b; }");
|
||||||
ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:9]: (style, inconclusive) Technically the member function 'B::func' can be const.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:9]: (style, inconclusive) Technically the member function 'B::func' can be const.\n", errout.str());
|
||||||
|
|
||||||
// base class has virtual function
|
// base class has virtual function
|
||||||
|
@ -5243,7 +5243,7 @@ private:
|
||||||
" B() : b(0) { }\n"
|
" B() : b(0) { }\n"
|
||||||
" int func();\n"
|
" int func();\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"int B::func() { return b; }\n");
|
"int B::func() { return b; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkConst("class A {\n"
|
checkConst("class A {\n"
|
||||||
|
@ -5256,7 +5256,7 @@ private:
|
||||||
" B() : b(0) { }\n"
|
" B() : b(0) { }\n"
|
||||||
" int func();\n"
|
" int func();\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"int B::func() { return b; }\n");
|
"int B::func() { return b; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// base class has no virtual function
|
// base class has no virtual function
|
||||||
|
@ -5302,7 +5302,7 @@ private:
|
||||||
" C() : c(0) { }\n"
|
" C() : c(0) { }\n"
|
||||||
" int func();\n"
|
" int func();\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"int C::func() { return c; }\n");
|
"int C::func() { return c; }");
|
||||||
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:5]: (style, inconclusive) Technically the member function 'A::func' can be const.\n"
|
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:5]: (style, inconclusive) Technically the member function 'A::func' can be const.\n"
|
||||||
"[test.cpp:14] -> [test.cpp:12]: (style, inconclusive) Technically the member function 'B::func' can be const.\n"
|
"[test.cpp:14] -> [test.cpp:12]: (style, inconclusive) Technically the member function 'B::func' can be const.\n"
|
||||||
"[test.cpp:21] -> [test.cpp:19]: (style, inconclusive) Technically the member function 'C::func' can be const.\n", errout.str());
|
"[test.cpp:21] -> [test.cpp:19]: (style, inconclusive) Technically the member function 'C::func' can be const.\n", errout.str());
|
||||||
|
@ -5348,7 +5348,7 @@ private:
|
||||||
" C() : c(0) { }\n"
|
" C() : c(0) { }\n"
|
||||||
" int func();\n"
|
" int func();\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"int C::func() { return c; }\n");
|
"int C::func() { return c; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// ticket #1311
|
// ticket #1311
|
||||||
|
@ -5394,7 +5394,7 @@ private:
|
||||||
" Z(int x, int y, int z) : Y(x, y), z(z) { }\n"
|
" Z(int x, int y, int z) : Y(x, y), z(z) { }\n"
|
||||||
" int getZ();\n"
|
" int getZ();\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"int Z::getZ() { return z; }\n");
|
"int Z::getZ() { return z; }");
|
||||||
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:5]: (style, inconclusive) Technically the member function 'X::getX' can be const.\n"
|
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:5]: (style, inconclusive) Technically the member function 'X::getX' can be const.\n"
|
||||||
"[test.cpp:14] -> [test.cpp:12]: (style, inconclusive) Technically the member function 'Y::getY' can be const.\n"
|
"[test.cpp:14] -> [test.cpp:12]: (style, inconclusive) Technically the member function 'Y::getY' can be const.\n"
|
||||||
"[test.cpp:21] -> [test.cpp:19]: (style, inconclusive) Technically the member function 'Z::getZ' can be const.\n", errout.str());
|
"[test.cpp:21] -> [test.cpp:19]: (style, inconclusive) Technically the member function 'Z::getZ' can be const.\n", errout.str());
|
||||||
|
|
|
@ -226,7 +226,7 @@ private:
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"Fred::Fred() :i(0)\n"
|
"Fred::Fred() :i(0)\n"
|
||||||
"{ }\n");
|
"{ }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct Fred\n"
|
check("struct Fred\n"
|
||||||
|
@ -235,7 +235,7 @@ private:
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"Fred::Fred()\n"
|
"Fred::Fred()\n"
|
||||||
"{ i = 0; }\n");
|
"{ i = 0; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct Fred\n"
|
check("struct Fred\n"
|
||||||
|
@ -244,7 +244,7 @@ private:
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"Fred::Fred()\n"
|
"Fred::Fred()\n"
|
||||||
"{ }\n");
|
"{ }");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'Fred::i' is not initialized in the constructor.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'Fred::i' is not initialized in the constructor.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,7 +321,7 @@ private:
|
||||||
void simple8() {
|
void simple8() {
|
||||||
check("struct Fred { int x; };\n"
|
check("struct Fred { int x; };\n"
|
||||||
"class Barney { Fred fred; };\n"
|
"class Barney { Fred fred; };\n"
|
||||||
"class Wilma { struct Betty { int x; } betty; };\n");
|
"class Wilma { struct Betty { int x; } betty; };");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) The class 'Barney' does not have a constructor.\n"
|
ASSERT_EQUALS("[test.cpp:2]: (style) The class 'Barney' does not have a constructor.\n"
|
||||||
"[test.cpp:3]: (style) The class 'Wilma' does not have a constructor.\n", errout.str());
|
"[test.cpp:3]: (style) The class 'Wilma' does not have a constructor.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -363,7 +363,7 @@ private:
|
||||||
" Fred() { Init(); }\n"
|
" Fred() { Init(); }\n"
|
||||||
" void Init(int i = 0);\n"
|
" void Init(int i = 0);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"void Fred::Init(int i) { x = i; }\n");
|
"void Fred::Init(int i) { x = i; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("class Fred {\n"
|
check("class Fred {\n"
|
||||||
|
@ -373,7 +373,7 @@ private:
|
||||||
" Fred() { Init(0); }\n"
|
" Fred() { Init(0); }\n"
|
||||||
" void Init(int i, int j = 0);\n"
|
" void Init(int i, int j = 0);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"void Fred::Init(int i, int j) { x = i; y = j; }\n");
|
"void Fred::Init(int i, int j) { x = i; y = j; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -881,7 +881,7 @@ private:
|
||||||
" Fred(const Fred &);\n"
|
" Fred(const Fred &);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"Fred::Fred() { };\n"
|
"Fred::Fred() { };\n"
|
||||||
"Fred::Fred(const Fred &) { };\n");
|
"Fred::Fred(const Fred &) { };");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("class Fred\n"
|
check("class Fred\n"
|
||||||
|
@ -930,7 +930,7 @@ private:
|
||||||
"A::A(){}\n"
|
"A::A(){}\n"
|
||||||
"A::B::B(int x){}\n"
|
"A::B::B(int x){}\n"
|
||||||
"A::B::C::C(int y){}\n"
|
"A::B::C::C(int y){}\n"
|
||||||
"A::B::C::D::D(int z){}\n");
|
"A::B::C::D::D(int z){}");
|
||||||
// Note that the example code is not compilable. The A constructor must
|
// Note that the example code is not compilable. The A constructor must
|
||||||
// explicitly initialize A::b. A warning for A::b is not necessary.
|
// explicitly initialize A::b. A warning for A::b is not necessary.
|
||||||
ASSERT_EQUALS("[test.cpp:20]: (warning) Member variable 'A::a' is not initialized in the constructor.\n"
|
ASSERT_EQUALS("[test.cpp:20]: (warning) Member variable 'A::a' is not initialized in the constructor.\n"
|
||||||
|
@ -960,7 +960,7 @@ private:
|
||||||
"A::A(){}\n"
|
"A::A(){}\n"
|
||||||
"A::B::B(int x){}\n"
|
"A::B::B(int x){}\n"
|
||||||
"A::B::C::C(int y){}\n"
|
"A::B::C::C(int y){}\n"
|
||||||
"A::B::C::D::D(const A::B::C::D & d){}\n");
|
"A::B::C::D::D(const A::B::C::D & d){}");
|
||||||
// Note that the example code is not compilable. The A constructor must
|
// Note that the example code is not compilable. The A constructor must
|
||||||
// explicitly initialize A::b. A warning for A::b is not necessary.
|
// explicitly initialize A::b. A warning for A::b is not necessary.
|
||||||
ASSERT_EQUALS("[test.cpp:20]: (warning) Member variable 'A::a' is not initialized in the constructor.\n"
|
ASSERT_EQUALS("[test.cpp:20]: (warning) Member variable 'A::a' is not initialized in the constructor.\n"
|
||||||
|
@ -991,7 +991,7 @@ private:
|
||||||
"A::A(){}\n"
|
"A::A(){}\n"
|
||||||
"A::B::B(int x){}\n"
|
"A::B::B(int x){}\n"
|
||||||
"A::B::C::C(int y){}\n"
|
"A::B::C::C(int y){}\n"
|
||||||
"A::B::C::D::D(const A::B::C::D::E & e){}\n");
|
"A::B::C::D::D(const A::B::C::D::E & e){}");
|
||||||
// Note that the example code is not compilable. The A constructor must
|
// Note that the example code is not compilable. The A constructor must
|
||||||
// explicitly initialize A::b. A warning for A::b is not necessary.
|
// explicitly initialize A::b. A warning for A::b is not necessary.
|
||||||
ASSERT_EQUALS("[test.cpp:21]: (warning) Member variable 'A::a' is not initialized in the constructor.\n"
|
ASSERT_EQUALS("[test.cpp:21]: (warning) Member variable 'A::a' is not initialized in the constructor.\n"
|
||||||
|
@ -1998,7 +1998,7 @@ private:
|
||||||
" Fred() : f{0, true} { }\n"
|
" Fred() : f{0, true} { }\n"
|
||||||
" float get() const\n"
|
" float get() const\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"float Fred::get() const { return g; }\n");
|
"float Fred::get() const { return g; }");
|
||||||
ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable 'Fred::g' is not initialized in the constructor.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable 'Fred::g' is not initialized in the constructor.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,8 +131,7 @@ private:
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" unsigned int val = 32;\n"
|
" unsigned int val = 32;\n"
|
||||||
" int i = val / -2; }\n"
|
" int i = val / -2; }");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Unsigned division. The result will be wrong.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Unsigned division. The result will be wrong.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +139,7 @@ private:
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" unsigned int val = 32;\n"
|
" unsigned int val = 32;\n"
|
||||||
" int i = -96 / val; }\n");
|
" int i = -96 / val; }");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Unsigned division. The result will be wrong.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Unsigned division. The result will be wrong.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -160,7 +160,7 @@ private:
|
||||||
" {\n"
|
" {\n"
|
||||||
" throw err;\n"
|
" throw err;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ private:
|
||||||
" {\n"
|
" {\n"
|
||||||
" throw err;\n"
|
" throw err;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ private:
|
||||||
" exception err2;\n"
|
" exception err2;\n"
|
||||||
" throw err2;\n"
|
" throw err2;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" const char def[] =\n"
|
" const char def[] =\n"
|
||||||
" \"abc\";\n"
|
" \"abc\";\n"
|
||||||
"}\n");
|
"}");
|
||||||
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ private:
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" \"abc\";\n"
|
" \"abc\";\n"
|
||||||
"}\n");
|
"}");
|
||||||
|
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant code: Found a statement that begins with string constant.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant code: Found a statement that begins with string constant.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ private:
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" const char *str[] = { \"abc\" };\n"
|
" const char *str[] = { \"abc\" };\n"
|
||||||
"}\n");
|
"}");
|
||||||
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ private:
|
||||||
"\"more \"\n"
|
"\"more \"\n"
|
||||||
"\"world\"\n"
|
"\"world\"\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"}\n");
|
"}");
|
||||||
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ private:
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" 50;\n"
|
" 50;\n"
|
||||||
"}\n");
|
"}");
|
||||||
|
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant code: Found a statement that begins with numeric constant.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant code: Found a statement that begins with numeric constant.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -133,13 +133,13 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
"{ 346.1,114.1 }, { 347.1,111.1 }\n"
|
"{ 346.1,114.1 }, { 347.1,111.1 }\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"}\n");
|
"}");
|
||||||
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void intarray() {
|
void intarray() {
|
||||||
check("int arr[] = { 100/2, 1*100 };\n");
|
check("int arr[] = { 100/2, 1*100 };");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ private:
|
||||||
check("struct st arr[] = {\n"
|
check("struct st arr[] = {\n"
|
||||||
" { 100/2, 1*100 }\n"
|
" { 100/2, 1*100 }\n"
|
||||||
" { 90, 70 }\n"
|
" { 90, 70 }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,14 +155,14 @@ private:
|
||||||
check("struct st arr[] = {\n"
|
check("struct st arr[] = {\n"
|
||||||
" { 100/2, 1*100 }\n"
|
" { 100/2, 1*100 }\n"
|
||||||
" { 90, 70 }\n"
|
" { 90, 70 }\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void conditionalcall() {
|
void conditionalcall() {
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" 0==x ? X() : Y();\n"
|
" 0==x ? X() : Y();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ private:
|
||||||
// #2462 - C++11 struct initialization
|
// #2462 - C++11 struct initialization
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" ABC abc{1,2,3};\n"
|
" ABC abc{1,2,3};\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// #2482 - false positive for empty struct
|
// #2482 - false positive for empty struct
|
||||||
|
|
|
@ -309,7 +309,7 @@ private:
|
||||||
" Z(){\n"
|
" Z(){\n"
|
||||||
" z[0] = 0;\n"
|
" z[0] = 0;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -474,7 +474,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" char str [8];\n"
|
" char str [8];\n"
|
||||||
" scanf (\"%70s\",str);\n"
|
" scanf (\"%70s\",str);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Width 70 given in format string (no. 1) is larger than destination buffer 'str[8]', use %7s to prevent overflowing it.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Width 70 given in format string (no. 1) is larger than destination buffer 'str[8]', use %7s to prevent overflowing it.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,7 +127,7 @@ private:
|
||||||
" char *p = malloc(10);\n"
|
" char *p = malloc(10);\n"
|
||||||
" p = NULL;\n"
|
" p = NULL;\n"
|
||||||
" free(p);\n"
|
" free(p);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.c:3]: (error) Memory leak: p\n", errout.str());
|
ASSERT_EQUALS("[test.c:3]: (error) Memory leak: p\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ private:
|
||||||
" char *p = malloc(10);\n"
|
" char *p = malloc(10);\n"
|
||||||
" char *q = p;\n"
|
" char *q = p;\n"
|
||||||
" free(q);\n"
|
" free(q);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ private:
|
||||||
" char *p = malloc(10);\n"
|
" char *p = malloc(10);\n"
|
||||||
" char *q = p + 1;\n"
|
" char *q = p + 1;\n"
|
||||||
" free(q - 1);\n"
|
" free(q - 1);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ private:
|
||||||
" char *a = malloc(10);\n"
|
" char *a = malloc(10);\n"
|
||||||
" a += 10;\n"
|
" a += 10;\n"
|
||||||
" free(a - 10);\n"
|
" free(a - 10);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" char *p = new char[100];\n"
|
" char *p = new char[100];\n"
|
||||||
" list += p;\n"
|
" list += p;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ private:
|
||||||
" char *p = malloc(10);\n"
|
" char *p = malloc(10);\n"
|
||||||
" p = strcpy(p,q);\n"
|
" p = strcpy(p,q);\n"
|
||||||
" free(p);\n"
|
" free(p);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ private:
|
||||||
check("void foo(struct str *d) {\n"
|
check("void foo(struct str *d) {\n"
|
||||||
" struct str *p = malloc(10);\n"
|
" struct str *p = malloc(10);\n"
|
||||||
" d->p = p;\n"
|
" d->p = p;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ private:
|
||||||
check("void foo(struct str *d) {\n"
|
check("void foo(struct str *d) {\n"
|
||||||
" struct str *p = malloc(10);\n"
|
" struct str *p = malloc(10);\n"
|
||||||
" d->p = &p->x;\n"
|
" d->p = &p->x;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ private:
|
||||||
" char *p = x();\n"
|
" char *p = x();\n"
|
||||||
" free(p);\n"
|
" free(p);\n"
|
||||||
" p = NULL;\n"
|
" p = NULL;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ private:
|
||||||
" if (x) { p = malloc(10); }\n"
|
" if (x) { p = malloc(10); }\n"
|
||||||
" if (!x) { p = NULL; }\n"
|
" if (!x) { p = NULL; }\n"
|
||||||
" free(p);\n"
|
" free(p);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,7 +436,7 @@ private:
|
||||||
" free(a);\n"
|
" free(a);\n"
|
||||||
" else\n"
|
" else\n"
|
||||||
" a = 0;\n"
|
" a = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.c:6]: (error) Memory leak: a\n", errout.str());
|
ASSERT_EQUALS("[test.c:6]: (error) Memory leak: a\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,7 +459,7 @@ private:
|
||||||
" for (i=0;i<5;i++) { }\n"
|
" for (i=0;i<5;i++) { }\n"
|
||||||
" if (x) { free(p) }\n"
|
" if (x) { free(p) }\n"
|
||||||
" else { a = p; }\n"
|
" else { a = p; }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -61,7 +61,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" char *cpwd;"
|
" char *cpwd;"
|
||||||
" crypt(pwd, cpwd);\n"
|
" crypt(pwd, cpwd);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'.\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
|
@ -69,14 +69,14 @@ private:
|
||||||
" char *pwd = getpass(\"Password:\");"
|
" char *pwd = getpass(\"Password:\");"
|
||||||
" char *cpwd;"
|
" char *cpwd;"
|
||||||
" crypt(pwd, cpwd);\n"
|
" crypt(pwd, cpwd);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'.\n", errout.str());
|
||||||
|
|
||||||
check("int f()\n"
|
check("int f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int crypt = 0;"
|
" int crypt = 0;"
|
||||||
" return crypt;\n"
|
" return crypt;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,14 +85,14 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" time_t t = 0;"
|
" time_t t = 0;"
|
||||||
" std::localtime(&t);\n"
|
" std::localtime(&t);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'.\n", errout.str());
|
||||||
|
|
||||||
// Passed as function argument
|
// Passed as function argument
|
||||||
check("int f()\n"
|
check("int f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" printf(\"Magic guess: %d\n\", getpwent());\n"
|
" printf(\"Magic guess: %d\n\", getpwent());\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'.\n", errout.str());
|
||||||
|
|
||||||
// Pass return value
|
// Pass return value
|
||||||
|
@ -100,35 +100,35 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" time_t t = 0;"
|
" time_t t = 0;"
|
||||||
" struct tm *foo = localtime(&t);\n"
|
" struct tm *foo = localtime(&t);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'.\n", errout.str());
|
||||||
|
|
||||||
// Access via global namespace
|
// Access via global namespace
|
||||||
check("int f()\n"
|
check("int f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" ::getpwent();\n"
|
" ::getpwent();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'.\n", errout.str());
|
||||||
|
|
||||||
// Be quiet on function definitions
|
// Be quiet on function definitions
|
||||||
check("int getpwent()\n"
|
check("int getpwent()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" return 123;\n"
|
" return 123;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// Be quiet on other namespaces
|
// Be quiet on other namespaces
|
||||||
check("int f()\n"
|
check("int f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" foobar::getpwent();\n"
|
" foobar::getpwent();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// Be quiet on class member functions
|
// Be quiet on class member functions
|
||||||
check("int f()\n"
|
check("int f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" foobar.getpwent();\n"
|
" foobar.getpwent();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -105,7 +105,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" while (tok);\n"
|
" while (tok);\n"
|
||||||
" tok = tok->next();\n"
|
" tok = tok->next();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (error) Possible null pointer dereference: tok - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (error) Possible null pointer dereference: tok - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
// #2681
|
// #2681
|
||||||
|
@ -133,7 +133,7 @@ private:
|
||||||
" while (tok && tok->str() != \";\")\n"
|
" while (tok && tok->str() != \";\")\n"
|
||||||
" tok = tok->next();\n"
|
" tok = tok->next();\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (error) Possible null pointer dereference: tok - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (error) Possible null pointer dereference: tok - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(Token &tok)\n"
|
check("void foo(Token &tok)\n"
|
||||||
|
@ -143,7 +143,7 @@ private:
|
||||||
" while (!tok)\n"
|
" while (!tok)\n"
|
||||||
" char c = tok.read();\n"
|
" char c = tok.read();\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
|
@ -154,7 +154,7 @@ private:
|
||||||
" tok = tok->next();\n"
|
" tok = tok->next();\n"
|
||||||
" if( !tok ) break;\n"
|
" if( !tok ) break;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
|
@ -164,7 +164,7 @@ private:
|
||||||
" while (tok && tok->str() != \";\")\n"
|
" while (tok && tok->str() != \";\")\n"
|
||||||
" tok = tok->next();\n"
|
" tok = tok->next();\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo(A*a)\n"
|
check("void foo(A*a)\n"
|
||||||
|
@ -179,7 +179,7 @@ private:
|
||||||
" a->b();\n"
|
" a->b();\n"
|
||||||
" break;\n"
|
" break;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// dereference in outer scope..
|
// dereference in outer scope..
|
||||||
|
@ -222,7 +222,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" else if (a->x == 2) { }\n"
|
" else if (a->x == 2) { }\n"
|
||||||
" if (a) { }\n"
|
" if (a) { }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// ticket #2134 - sizeof doesn't dereference
|
// ticket #2134 - sizeof doesn't dereference
|
||||||
|
@ -266,14 +266,14 @@ private:
|
||||||
" int a = abc->a;\n"
|
" int a = abc->a;\n"
|
||||||
" if (!abc)\n"
|
" if (!abc)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(struct ABC *abc) {\n"
|
check("void foo(struct ABC *abc) {\n"
|
||||||
" bar(abc->a);\n"
|
" bar(abc->a);\n"
|
||||||
" if (!abc)\n"
|
" if (!abc)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(ABC *abc) {\n"
|
check("void foo(ABC *abc) {\n"
|
||||||
|
@ -297,14 +297,14 @@ private:
|
||||||
" abc->next->a = 0;\n"
|
" abc->next->a = 0;\n"
|
||||||
" if (abc->next)\n"
|
" if (abc->next)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check it against null.\n", "", errout.str());
|
TODO_ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check it against null.\n", "", errout.str());
|
||||||
|
|
||||||
check("void foo(ABC *abc) {\n"
|
check("void foo(ABC *abc) {\n"
|
||||||
" abc->a = 0;\n"
|
" abc->a = 0;\n"
|
||||||
" if (abc && abc->b == 0)\n"
|
" if (abc && abc->b == 0)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
// ok dereferencing in a condition
|
// ok dereferencing in a condition
|
||||||
|
@ -313,7 +313,7 @@ private:
|
||||||
" if (abc && abc->a);\n"
|
" if (abc && abc->a);\n"
|
||||||
" if (!abc)\n"
|
" if (!abc)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f(struct ABC *abc) {\n"
|
check("void f(struct ABC *abc) {\n"
|
||||||
|
@ -367,7 +367,7 @@ private:
|
||||||
"out:\n"
|
"out:\n"
|
||||||
" if (!abc)\n"
|
" if (!abc)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// loops..
|
// loops..
|
||||||
|
@ -381,7 +381,7 @@ private:
|
||||||
" --a;\n"
|
" --a;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" while (a > 0);\n"
|
" while (a > 0);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
|
@ -393,7 +393,7 @@ private:
|
||||||
" if (!tok)\n"
|
" if (!tok)\n"
|
||||||
" return;\n"
|
" return;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// dynamic_cast..
|
// dynamic_cast..
|
||||||
|
@ -402,7 +402,7 @@ private:
|
||||||
" int a = abc->a;\n"
|
" int a = abc->a;\n"
|
||||||
" if (!dynamic_cast<DEF *>(abc))\n"
|
" if (!dynamic_cast<DEF *>(abc))\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// #2641 - global pointer, function call
|
// #2641 - global pointer, function call
|
||||||
|
@ -486,21 +486,21 @@ private:
|
||||||
" *p = 0;\n"
|
" *p = 0;\n"
|
||||||
" if (!p)\n"
|
" if (!p)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(int *p)\n"
|
check("void foo(int *p)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" *p = 0;\n"
|
" *p = 0;\n"
|
||||||
" if (p) { }\n"
|
" if (p) { }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(int *p)\n"
|
check("void foo(int *p)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" *p = 0;\n"
|
" *p = 0;\n"
|
||||||
" if (p || q) { }\n"
|
" if (p || q) { }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(int *p)\n"
|
check("void foo(int *p)\n"
|
||||||
|
@ -508,7 +508,7 @@ private:
|
||||||
" bar(*p);\n"
|
" bar(*p);\n"
|
||||||
" if (!p)\n"
|
" if (!p)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(char *p)\n"
|
check("void foo(char *p)\n"
|
||||||
|
@ -516,14 +516,14 @@ private:
|
||||||
" strcpy(p, \"abc\");\n"
|
" strcpy(p, \"abc\");\n"
|
||||||
" if (!p)\n"
|
" if (!p)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(char *p)\n"
|
check("void foo(char *p)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" if (*p == 0) { }\n"
|
" if (*p == 0) { }\n"
|
||||||
" if (!p) { }\n"
|
" if (!p) { }\n"
|
||||||
"}\n");
|
"}");
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", "", errout.str());
|
TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", "", errout.str());
|
||||||
|
|
||||||
// no error
|
// no error
|
||||||
|
@ -533,7 +533,7 @@ private:
|
||||||
" f(&p);\n"
|
" f(&p);\n"
|
||||||
" if (!p)\n"
|
" if (!p)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
|
@ -552,7 +552,7 @@ private:
|
||||||
" *p = 0;\n"
|
" *p = 0;\n"
|
||||||
" if (!p)\n"
|
" if (!p)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo(int x)\n"
|
check("void foo(int x)\n"
|
||||||
|
@ -568,7 +568,7 @@ private:
|
||||||
" int var1 = p ? *p : 0;\n"
|
" int var1 = p ? *p : 0;\n"
|
||||||
" if (!p)\n"
|
" if (!p)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo(int *p)\n"
|
check("void foo(int *p)\n"
|
||||||
|
@ -576,7 +576,7 @@ private:
|
||||||
" int var1 = x ? *p : 5;\n"
|
" int var1 = x ? *p : 5;\n"
|
||||||
" if (!p)\n"
|
" if (!p)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
TODO_ASSERT_EQUALS("error", "", errout.str());
|
TODO_ASSERT_EQUALS("error", "", errout.str());
|
||||||
|
|
||||||
// Ticket #3125
|
// Ticket #3125
|
||||||
|
@ -585,7 +585,7 @@ private:
|
||||||
" int var1 = p ? (p->a) : 0;\n"
|
" int var1 = p ? (p->a) : 0;\n"
|
||||||
" if (!p)\n"
|
" if (!p)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo(ABC *p)\n"
|
check("void foo(ABC *p)\n"
|
||||||
|
@ -593,7 +593,7 @@ private:
|
||||||
" int var1 = p ? (1 + p->a) : 0;\n"
|
" int var1 = p ? (1 + p->a) : 0;\n"
|
||||||
" if (!p)\n"
|
" if (!p)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
|
@ -625,7 +625,7 @@ private:
|
||||||
" break;\n"
|
" break;\n"
|
||||||
" else\n"
|
" else\n"
|
||||||
" p = p->next();\n"
|
" p = p->next();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f(Document *doc) {\n"
|
check("void f(Document *doc) {\n"
|
||||||
|
@ -661,7 +661,7 @@ private:
|
||||||
" p = p->next;\n"
|
" p = p->next;\n"
|
||||||
" if (!p)\n"
|
" if (!p)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo(x *p)\n"
|
check("void foo(x *p)\n"
|
||||||
|
@ -669,7 +669,7 @@ private:
|
||||||
" p = bar(p->next);\n"
|
" p = bar(p->next);\n"
|
||||||
" if (!p)\n"
|
" if (!p)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo(x *p)\n"
|
check("void foo(x *p)\n"
|
||||||
|
@ -677,7 +677,7 @@ private:
|
||||||
" p = aa->bar(p->next);\n"
|
" p = aa->bar(p->next);\n"
|
||||||
" if (!p)\n"
|
" if (!p)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo(x *p)\n"
|
check("void foo(x *p)\n"
|
||||||
|
@ -685,7 +685,7 @@ private:
|
||||||
" p = *p2 = p->next;\n"
|
" p = *p2 = p->next;\n"
|
||||||
" if (!p)\n"
|
" if (!p)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo(struct ABC *abc)\n"
|
check("void foo(struct ABC *abc)\n"
|
||||||
|
@ -693,7 +693,7 @@ private:
|
||||||
" abc = abc ? abc->next : 0;\n"
|
" abc = abc ? abc->next : 0;\n"
|
||||||
" if (!abc)\n"
|
" if (!abc)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f(struct ABC *abc) {\n" // #4523
|
check("void f(struct ABC *abc) {\n" // #4523
|
||||||
|
@ -711,14 +711,14 @@ private:
|
||||||
check("int f(Item *item) {\n"
|
check("int f(Item *item) {\n"
|
||||||
" x = item ? ab(item->x) : 0;\n"
|
" x = item ? ab(item->x) : 0;\n"
|
||||||
" if (item) { }\n"
|
" if (item) { }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("int f(Item *item) {\n"
|
check("int f(Item *item) {\n"
|
||||||
" item->x = 0;\n"
|
" item->x = 0;\n"
|
||||||
" a = b ? c : d;\n"
|
" a = b ? c : d;\n"
|
||||||
" if (item) { }\n"
|
" if (item) { }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (error) Possible null pointer dereference: item - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (error) Possible null pointer dereference: item - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
check("BOOL GotoFlyAnchor()\n" // #2243
|
check("BOOL GotoFlyAnchor()\n" // #2243
|
||||||
|
@ -730,7 +730,7 @@ private:
|
||||||
"\n"
|
"\n"
|
||||||
" if( !pFrm )\n"
|
" if( !pFrm )\n"
|
||||||
" return FALSE;\n"
|
" return FALSE;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// Ticket #2463
|
// Ticket #2463
|
||||||
|
@ -750,7 +750,7 @@ private:
|
||||||
" break;\n"
|
" break;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// #2525 - sizeof
|
// #2525 - sizeof
|
||||||
|
@ -796,7 +796,7 @@ private:
|
||||||
" char c = a.c();\n"
|
" char c = a.c();\n"
|
||||||
" if (!a)\n"
|
" if (!a)\n"
|
||||||
" return;\n"
|
" return;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -811,7 +811,7 @@ private:
|
||||||
" else if (a == 2)\n"
|
" else if (a == 2)\n"
|
||||||
" p = new FooCar;\n"
|
" p = new FooCar;\n"
|
||||||
" p->abcd();\n"
|
" p->abcd();\n"
|
||||||
"}\n");
|
"}");
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:8]: (error) Possible null pointer dereference: p\n",
|
TODO_ASSERT_EQUALS("[test.cpp:8]: (error) Possible null pointer dereference: p\n",
|
||||||
"", errout.str());
|
"", errout.str());
|
||||||
|
|
||||||
|
@ -820,21 +820,21 @@ private:
|
||||||
" int *p = 0;\n"
|
" int *p = 0;\n"
|
||||||
" int *q = p;\n"
|
" int *q = p;\n"
|
||||||
" q[0] = 0;\n"
|
" q[0] = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: q\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: q\n", errout.str());
|
||||||
|
|
||||||
check("static void foo()\n"
|
check("static void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int *p = 0;\n"
|
" int *p = 0;\n"
|
||||||
" int &r = *p;\n"
|
" int &r = *p;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference\n", errout.str());
|
||||||
|
|
||||||
check("static void foo(int x)\n"
|
check("static void foo(int x)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int *p = 0;\n"
|
" int *p = 0;\n"
|
||||||
" int y = 5 + *p;\n"
|
" int y = 5 + *p;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference\n", errout.str());
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -857,7 +857,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" int *p(0);\n"
|
" int *p(0);\n"
|
||||||
" std::cout << *p;"
|
" std::cout << *p;"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
|
@ -867,14 +867,14 @@ private:
|
||||||
" delete c;\n"
|
" delete c;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" c[0] = 0;\n"
|
" c[0] = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (error) Possible null pointer dereference: c\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (error) Possible null pointer dereference: c\n", errout.str());
|
||||||
|
|
||||||
check("static void foo()\n"
|
check("static void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int *p = 0;\n"
|
" int *p = 0;\n"
|
||||||
" if (3 > *p);\n"
|
" if (3 > *p);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
|
@ -883,7 +883,7 @@ private:
|
||||||
" char *c = 0;\n"
|
" char *c = 0;\n"
|
||||||
" *c = 0;\n"
|
" *c = 0;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference\n", errout.str());
|
||||||
|
|
||||||
// no false positive..
|
// no false positive..
|
||||||
|
@ -892,7 +892,7 @@ private:
|
||||||
" Foo *p = 0;\n"
|
" Foo *p = 0;\n"
|
||||||
" p = new Foo;\n"
|
" p = new Foo;\n"
|
||||||
" p->abcd();\n"
|
" p->abcd();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("static void foo()\n"
|
check("static void foo()\n"
|
||||||
|
@ -901,7 +901,7 @@ private:
|
||||||
" if (!p)\n"
|
" if (!p)\n"
|
||||||
" return;\n"
|
" return;\n"
|
||||||
" p->abcd();\n"
|
" p->abcd();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("static void foo()\n"
|
check("static void foo()\n"
|
||||||
|
@ -909,7 +909,7 @@ private:
|
||||||
" int *p = 0;\n"
|
" int *p = 0;\n"
|
||||||
" exit();\n"
|
" exit();\n"
|
||||||
" *p = 0;\n"
|
" *p = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("static void foo(int a)\n"
|
check("static void foo(int a)\n"
|
||||||
|
@ -917,26 +917,26 @@ private:
|
||||||
" Foo *p = 0;\n"
|
" Foo *p = 0;\n"
|
||||||
" if (a && p)\n"
|
" if (a && p)\n"
|
||||||
" p->do_something();\n"
|
" p->do_something();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" Foo *p = 0;\n"
|
" Foo *p = 0;\n"
|
||||||
" bool b = (p && (p->type() == 1));\n"
|
" bool b = (p && (p->type() == 1));\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int sz = sizeof((*(struct dummy *)0).x);\n"
|
" int sz = sizeof((*(struct dummy *)0).x);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void get_offset(long &offset)\n"
|
check("void get_offset(long &offset)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" mystruct * temp; temp = 0;\n"
|
" mystruct * temp; temp = 0;\n"
|
||||||
" offset = (long)(&(temp->z));\n"
|
" offset = (long)(&(temp->z));\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// Ticket #1893 - try/catch inside else
|
// Ticket #1893 - try/catch inside else
|
||||||
|
@ -955,7 +955,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" *Q=1;\n"
|
" *Q=1;\n"
|
||||||
" return Q;\n"
|
" return Q;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("int *test(int *Z)\n"
|
check("int *test(int *Z)\n"
|
||||||
|
@ -971,7 +971,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" *Q=1;\n"
|
" *Q=1;\n"
|
||||||
" return Q;\n"
|
" return Q;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:12]: (error) Possible null pointer dereference: Q\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:12]: (error) Possible null pointer dereference: Q\n", errout.str());
|
||||||
|
|
||||||
// Ticket #2052 (false positive for 'else continue;')
|
// Ticket #2052 (false positive for 'else continue;')
|
||||||
|
@ -991,7 +991,7 @@ private:
|
||||||
" void (*f)();\n"
|
" void (*f)();\n"
|
||||||
" f = 0;\n"
|
" f = 0;\n"
|
||||||
" f();\n"
|
" f();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: f\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: f\n", errout.str());
|
||||||
|
|
||||||
check("static void foo()\n"
|
check("static void foo()\n"
|
||||||
|
@ -1000,7 +1000,7 @@ private:
|
||||||
" int *p2 = 0;\n"
|
" int *p2 = 0;\n"
|
||||||
" int r = *p;\n"
|
" int r = *p;\n"
|
||||||
" int r2 = *p2;\n"
|
" int r2 = *p2;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference\n"
|
ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference\n"
|
||||||
"[test.cpp:6]: (error) Null pointer dereference\n", errout.str());
|
"[test.cpp:6]: (error) Null pointer dereference\n", errout.str());
|
||||||
|
|
||||||
|
@ -1010,7 +1010,7 @@ private:
|
||||||
" for (int i = 0; i < 10; ++i) {\n"
|
" for (int i = 0; i < 10; ++i) {\n"
|
||||||
" int x = *p + 1;\n"
|
" int x = *p + 1;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
|
||||||
|
|
||||||
check("void f(int a) {\n"
|
check("void f(int a) {\n"
|
||||||
|
@ -1078,7 +1078,7 @@ private:
|
||||||
" for (int i = 0; i < n; i++) {\n"
|
" for (int i = 0; i < n; i++) {\n"
|
||||||
" argv32[i] = 0;\n"
|
" argv32[i] = 0;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// No false negative:
|
// No false negative:
|
||||||
|
@ -1093,7 +1093,7 @@ private:
|
||||||
" for (int i = 0; i < n; i++) {\n"
|
" for (int i = 0; i < n; i++) {\n"
|
||||||
" argv32[i] = 0;\n"
|
" argv32[i] = 0;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
TODO_ASSERT_EQUALS("error",
|
TODO_ASSERT_EQUALS("error",
|
||||||
"", errout.str());
|
"", errout.str());
|
||||||
|
|
||||||
|
@ -1127,13 +1127,13 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" const char * x = 0;\n"
|
" const char * x = 0;\n"
|
||||||
" strdup(x);\n"
|
" strdup(x);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str());
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" char const * x = 0;\n"
|
" char const * x = 0;\n"
|
||||||
" strdup(x);\n"
|
" strdup(x);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1142,7 +1142,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" std::string * x = 0;\n"
|
" std::string * x = 0;\n"
|
||||||
" *x = \"test\";\n"
|
" *x = \"test\";\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1151,7 +1151,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" struct my_type* p = 0;\n"
|
" struct my_type* p = 0;\n"
|
||||||
" p->x = 0;\n"
|
" p->x = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
|
||||||
|
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
|
@ -1159,7 +1159,7 @@ private:
|
||||||
" struct my_type* p;\n"
|
" struct my_type* p;\n"
|
||||||
" p = 0;\n"
|
" p = 0;\n"
|
||||||
" p->x = 0;\n"
|
" p->x = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1168,14 +1168,14 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" my_type* p = 0;\n"
|
" my_type* p = 0;\n"
|
||||||
" return p->x;\n"
|
" return p->x;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
|
||||||
|
|
||||||
check("int foo()\n"
|
check("int foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" struct my_type* p = 0;\n"
|
" struct my_type* p = 0;\n"
|
||||||
" return p->x;\n"
|
" return p->x;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
|
||||||
|
|
||||||
check("int foo()\n"
|
check("int foo()\n"
|
||||||
|
@ -1183,7 +1183,7 @@ private:
|
||||||
" my_type* p;\n"
|
" my_type* p;\n"
|
||||||
" p = 0;\n"
|
" p = 0;\n"
|
||||||
" return p->x;\n"
|
" return p->x;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());
|
||||||
|
|
||||||
check("int foo()\n"
|
check("int foo()\n"
|
||||||
|
@ -1191,7 +1191,7 @@ private:
|
||||||
" struct my_type* p;\n"
|
" struct my_type* p;\n"
|
||||||
" p = 0;\n"
|
" p = 0;\n"
|
||||||
" return p->x;\n"
|
" return p->x;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1221,7 +1221,7 @@ private:
|
||||||
" s.d=NULL;\n"
|
" s.d=NULL;\n"
|
||||||
" double *pd = s.d;\n"
|
" double *pd = s.d;\n"
|
||||||
" *pd = 10;\n"
|
" *pd = 10;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:10]: (error) Null pointer dereference\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:10]: (error) Null pointer dereference\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1229,13 +1229,13 @@ private:
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" strcpy(bar, 0);\n"
|
" strcpy(bar, 0);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference\n", errout.str());
|
||||||
|
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" memcmp(bar(xyz()), 0, 123);\n"
|
" memcmp(bar(xyz()), 0, 123);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference\n", errout.str());
|
||||||
|
|
||||||
check("void foo(const char *s)\n"
|
check("void foo(const char *s)\n"
|
||||||
|
@ -1244,7 +1244,7 @@ private:
|
||||||
" frexp(1.0, p);\n"
|
" frexp(1.0, p);\n"
|
||||||
" char *q = 0;\n"
|
" char *q = 0;\n"
|
||||||
" frexp(1.0, q);\n"
|
" frexp(1.0, q);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (error) Possible null pointer dereference: q\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (error) Possible null pointer dereference: q\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1358,48 +1358,48 @@ private:
|
||||||
" if (!p) {\n"
|
" if (!p) {\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" *p = 0;\n"
|
" *p = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(char *p) {\n"
|
check("void foo(char *p) {\n"
|
||||||
" if (NULL == p) {\n"
|
" if (NULL == p) {\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" *p = 0;\n"
|
" *p = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(char *p) {\n"
|
check("void foo(char *p) {\n"
|
||||||
" if (p == NULL) {\n"
|
" if (p == NULL) {\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" *p = 0;\n"
|
" *p = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(char *p) {\n"
|
check("void foo(char *p) {\n"
|
||||||
" if (p == NULL) {\n"
|
" if (p == NULL) {\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" printf(\"%c\", *p);\n"
|
" printf(\"%c\", *p);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(char *p) {\n"
|
check("void foo(char *p) {\n"
|
||||||
" if (p && *p == 0) {\n"
|
" if (p && *p == 0) {\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" printf(\"%c\", *p);\n"
|
" printf(\"%c\", *p);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(char *p) {\n"
|
check("void foo(char *p) {\n"
|
||||||
" if (p && *p == 0) {\n"
|
" if (p && *p == 0) {\n"
|
||||||
" } else { *p = 0; }\n"
|
" } else { *p = 0; }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(char *p) {\n"
|
check("void foo(char *p) {\n"
|
||||||
" if (p) {\n"
|
" if (p) {\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" strcpy(p, \"abc\");\n"
|
" strcpy(p, \"abc\");\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(char *p) {\n"
|
check("void foo(char *p) {\n"
|
||||||
|
@ -1407,7 +1407,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" bar();\n"
|
" bar();\n"
|
||||||
" strcpy(p, \"abc\");\n"
|
" strcpy(p, \"abc\");\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(abc *p) {\n"
|
check("void foo(abc *p) {\n"
|
||||||
|
@ -1415,7 +1415,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" else if (!p->x) {\n"
|
" else if (!p->x) {\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo(char *p) {\n"
|
check("void foo(char *p) {\n"
|
||||||
|
@ -1423,7 +1423,7 @@ private:
|
||||||
" abort();\n"
|
" abort();\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" *p = 0;\n"
|
" *p = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo(char *p) {\n"
|
check("void foo(char *p) {\n"
|
||||||
|
@ -1439,7 +1439,7 @@ private:
|
||||||
" (*bail)();\n"
|
" (*bail)();\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" *p = 0;\n"
|
" *p = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo(char *p) {\n"
|
check("void foo(char *p) {\n"
|
||||||
|
@ -1447,7 +1447,7 @@ private:
|
||||||
" throw x;\n"
|
" throw x;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" *p = 0;\n"
|
" *p = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo(char *p) {\n"
|
check("void foo(char *p) {\n"
|
||||||
|
@ -1455,7 +1455,7 @@ private:
|
||||||
" ab.abort();\n"
|
" ab.abort();\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" *p = 0;\n"
|
" *p = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo(char *p) {\n"
|
check("void foo(char *p) {\n"
|
||||||
|
@ -1487,7 +1487,7 @@ private:
|
||||||
" if (!a) {\n"
|
" if (!a) {\n"
|
||||||
" a.x();\n"
|
" a.x();\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// This is why this check can't be used on the simplified token list
|
// This is why this check can't be used on the simplified token list
|
||||||
|
@ -1495,7 +1495,7 @@ private:
|
||||||
" if (!dynamic_cast<bar *>(foo)) {\n"
|
" if (!dynamic_cast<bar *>(foo)) {\n"
|
||||||
" *foo = 0;\n"
|
" *foo = 0;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// ticket: #2300 - calling unknown function that may initialize the pointer
|
// ticket: #2300 - calling unknown function that may initialize the pointer
|
||||||
|
@ -1505,7 +1505,7 @@ private:
|
||||||
" initfred();\n"
|
" initfred();\n"
|
||||||
" fred->x = 0;\n"
|
" fred->x = 0;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// ticket #1219
|
// ticket #1219
|
||||||
|
@ -1514,7 +1514,7 @@ private:
|
||||||
" return;\n"
|
" return;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" *p = 0;\n"
|
" *p = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
// #2467 - unknown macro may terminate the application
|
// #2467 - unknown macro may terminate the application
|
||||||
|
@ -1618,7 +1618,7 @@ private:
|
||||||
check("int foo(struct Fred *fred) {\n"
|
check("int foo(struct Fred *fred) {\n"
|
||||||
" if (fred) { int a = 0; }\n"
|
" if (fred) { int a = 0; }\n"
|
||||||
" return fred->a;\n"
|
" return fred->a;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (error) Possible null pointer dereference: fred - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (error) Possible null pointer dereference: fred - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
// #2789 - assign and check pointer
|
// #2789 - assign and check pointer
|
||||||
|
@ -1626,7 +1626,7 @@ private:
|
||||||
" char *p;\n"
|
" char *p;\n"
|
||||||
" if (!(p=x())) { }\n"
|
" if (!(p=x())) { }\n"
|
||||||
" *p = 0;\n"
|
" *p = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
||||||
|
|
||||||
// check, assign and use
|
// check, assign and use
|
||||||
|
@ -1707,7 +1707,7 @@ private:
|
||||||
check("void f(char *s) {\n" // #3358
|
check("void f(char *s) {\n" // #3358
|
||||||
" if (s==0);\n"
|
" if (s==0);\n"
|
||||||
" strcpy(a, s?b:c);\n"
|
" strcpy(a, s?b:c);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// sizeof
|
// sizeof
|
||||||
|
@ -1743,7 +1743,7 @@ private:
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" char *p = 0;\n"
|
" char *p = 0;\n"
|
||||||
" strcpy(p, \"abcd\");\n"
|
" strcpy(p, \"abcd\");\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference\n", errout.str());
|
||||||
|
|
||||||
// Ticket #1171
|
// Ticket #1171
|
||||||
|
@ -1816,7 +1816,7 @@ private:
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" char *s = 0;\n"
|
" char *s = 0;\n"
|
||||||
" printf(\"%s\", s == 0 ? a : s);\n"
|
" printf(\"%s\", s == 0 ? a : s);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
|
|
|
@ -92,14 +92,14 @@ private:
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" bsd_signal(SIGABRT, SIG_IGN);\n"
|
" bsd_signal(SIGABRT, SIG_IGN);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) Obsolete function 'bsd_signal' called. It is recommended to use the function 'sigaction' instead.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) Obsolete function 'bsd_signal' called. It is recommended to use the function 'sigaction' instead.\n", errout.str());
|
||||||
|
|
||||||
check("int f()\n"
|
check("int f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int bsd_signal(0);\n"
|
" int bsd_signal(0);\n"
|
||||||
" return bsd_signal;\n"
|
" return bsd_signal;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ private:
|
||||||
" if(!hp = gethostbyname('127.0.0.1')) {\n"
|
" if(!hp = gethostbyname('127.0.0.1')) {\n"
|
||||||
" exit(1);\n"
|
" exit(1);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) Obsolete function 'gethostbyname' called. It is recommended to use the function 'getaddrinfo' instead.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) Obsolete function 'gethostbyname' called. It is recommended to use the function 'getaddrinfo' instead.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ private:
|
||||||
" if(!hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET)) {\n"
|
" if(!hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET)) {\n"
|
||||||
" exit(1);\n"
|
" exit(1);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (style) Obsolete function 'gethostbyaddr' called. It is recommended to use the function 'getnameinfo' instead.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (style) Obsolete function 'gethostbyaddr' called. It is recommended to use the function 'getnameinfo' instead.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ private:
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" usleep( 1000 );\n"
|
" usleep( 1000 );\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) Obsolete function 'usleep' called. It is recommended to use the 'nanosleep' or 'setitimer' function instead.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) Obsolete function 'usleep' called. It is recommended to use the 'nanosleep' or 'setitimer' function instead.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ private:
|
||||||
"int main()\n"
|
"int main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" n1::index();\n"
|
" n1::index();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("std::size_t f()\n"
|
check("std::size_t f()\n"
|
||||||
|
@ -151,19 +151,19 @@ private:
|
||||||
" std::size_t index(0);\n"
|
" std::size_t index(0);\n"
|
||||||
" index++;\n"
|
" index++;\n"
|
||||||
" return index;\n"
|
" return index;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("int f()\n"
|
check("int f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" return this->index();\n"
|
" return this->index();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int index( 0 );\n"
|
" int index( 0 );\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("const char f()\n"
|
check("const char f()\n"
|
||||||
|
@ -171,7 +171,7 @@ private:
|
||||||
" const char var[6] = 'index';\n"
|
" const char var[6] = 'index';\n"
|
||||||
" const char i = index(var, 0);\n"
|
" const char i = index(var, 0);\n"
|
||||||
" return i;\n"
|
" return i;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) Obsolete function 'index' called. It is recommended to use the function 'strchr' instead.\n",
|
ASSERT_EQUALS("[test.cpp:4]: (style) Obsolete function 'index' called. It is recommended to use the function 'strchr' instead.\n",
|
||||||
errout.str());
|
errout.str());
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ private:
|
||||||
void test_qt_index() {
|
void test_qt_index() {
|
||||||
check("void TDataModel::forceRowRefresh(int row) {\n"
|
check("void TDataModel::forceRowRefresh(int row) {\n"
|
||||||
" emit dataChanged(index(row, 0), index(row, columnCount() - 1));\n"
|
" emit dataChanged(index(row, 0), index(row, columnCount() - 1));\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) Obsolete function 'index' called. It is recommended to use the function 'strchr' instead.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (style) Obsolete function 'index' called. It is recommended to use the function 'strchr' instead.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,14 +187,14 @@ private:
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int rindex( 0 );\n"
|
" int rindex( 0 );\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" const char var[7] = 'rindex';\n"
|
" const char var[7] = 'rindex';\n"
|
||||||
" print(rindex(var, 0));\n"
|
" print(rindex(var, 0));\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) Obsolete function 'rindex' called. It is recommended to use the function 'strrchr' instead.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) Obsolete function 'rindex' called. It is recommended to use the function 'strrchr' instead.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ private:
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" Fred() : index(0) { }\n"
|
" Fred() : index(0) { }\n"
|
||||||
" int index;\n"
|
" int index;\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ private:
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" char *x = gets();\n"
|
" char *x = gets();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) Obsolete function 'gets' called. It is recommended to use the function 'fgets' instead.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) Obsolete function 'gets' called. It is recommended to use the function 'fgets' instead.\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
|
@ -246,7 +246,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" int b ; b = ftime ( 1 ) ;\n"
|
" int b ; b = ftime ( 1 ) ;\n"
|
||||||
" return 0 ;\n"
|
" return 0 ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,7 +255,7 @@ private:
|
||||||
check("void f(char * str)\n"
|
check("void f(char * str)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" char *x = std::gets(str);\n"
|
" char *x = std::gets(str);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) Obsolete function 'gets' called. It is recommended to use the function 'fgets' instead.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) Obsolete function 'gets' called. It is recommended to use the function 'fgets' instead.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,7 +265,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" char *x = std::gets(str);\n"
|
" char *x = std::gets(str);\n"
|
||||||
" usleep( 1000 );\n"
|
" usleep( 1000 );\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) Obsolete function 'gets' called. It is recommended to use the function 'fgets' instead.\n"
|
ASSERT_EQUALS("[test.cpp:3]: (style) Obsolete function 'gets' called. It is recommended to use the function 'fgets' instead.\n"
|
||||||
"[test.cpp:4]: (style) Obsolete function 'usleep' called. It is recommended to use the 'nanosleep' or 'setitimer' function instead.\n", errout.str());
|
"[test.cpp:4]: (style) Obsolete function 'usleep' called. It is recommended to use the 'nanosleep' or 'setitimer' function instead.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -276,14 +276,14 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" char s [ 10 ] ;\n"
|
" char s [ 10 ] ;\n"
|
||||||
" gets ( s ) ;\n"
|
" gets ( s ) ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (style) Obsolete function 'gets' called. It is recommended to use the function 'fgets' instead.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (style) Obsolete function 'gets' called. It is recommended to use the function 'fgets' instead.\n", errout.str());
|
||||||
|
|
||||||
check("int getcontext(ucontext_t *ucp);\n"
|
check("int getcontext(ucontext_t *ucp);\n"
|
||||||
"int f (ucontext_t *ucp)\n"
|
"int f (ucontext_t *ucp)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" getcontext ( ucp ) ;\n"
|
" getcontext ( ucp ) ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) Obsolete function 'getcontext' called. Due to portability issues, applications are recommended to be rewritten to use POSIX threads.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) Obsolete function 'getcontext' called. Due to portability issues, applications are recommended to be rewritten to use POSIX threads.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +293,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" char s [ 10 ] ;\n"
|
" char s [ 10 ] ;\n"
|
||||||
" gets ( s ) ;\n"
|
" gets ( s ) ;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -83,7 +83,7 @@ private:
|
||||||
" k--;\n"
|
" k--;\n"
|
||||||
" std::cout << k << std::endl;\n"
|
" std::cout << k << std::endl;\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("class K {};"
|
check("class K {};"
|
||||||
|
@ -94,7 +94,7 @@ private:
|
||||||
" k++;\n"
|
" k++;\n"
|
||||||
" std::cout << k << std::endl;\n"
|
" std::cout << k << std::endl;\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||||
|
|
||||||
check("struct K {};"
|
check("struct K {};"
|
||||||
|
@ -102,7 +102,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" K k(0);\n"
|
" K k(0);\n"
|
||||||
" k++;\n"
|
" k++;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||||
|
|
||||||
check("union K {};"
|
check("union K {};"
|
||||||
|
@ -110,7 +110,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" K k(0);\n"
|
" K k(0);\n"
|
||||||
" k++;\n"
|
" k++;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||||
|
|
||||||
check("class K {};"
|
check("class K {};"
|
||||||
|
@ -123,7 +123,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" std::cout << k << std::endl;\n"
|
" std::cout << k << std::endl;\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||||
|
|
||||||
check("class K {};"
|
check("class K {};"
|
||||||
|
@ -137,7 +137,7 @@ private:
|
||||||
" k++;\n"
|
" k++;\n"
|
||||||
" std::cout << k << std::endl;\n"
|
" std::cout << k << std::endl;\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||||
|
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ private:
|
||||||
" k--;\n"
|
" k--;\n"
|
||||||
" std::cout << k << std::endl;\n"
|
" std::cout << k << std::endl;\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||||
|
|
||||||
check("class K {};"
|
check("class K {};"
|
||||||
|
@ -160,7 +160,7 @@ private:
|
||||||
" ++k;\n"
|
" ++k;\n"
|
||||||
" std::cout << k << std::endl;\n"
|
" std::cout << k << std::endl;\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("class K {};"
|
check("class K {};"
|
||||||
|
@ -171,7 +171,7 @@ private:
|
||||||
" --k;\n"
|
" --k;\n"
|
||||||
" std::cout << k << std::endl;\n"
|
" std::cout << k << std::endl;\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -183,7 +183,7 @@ private:
|
||||||
" std::cout << i << std::endl;\n"
|
" std::cout << i << std::endl;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("class K {};\n"
|
check("class K {};\n"
|
||||||
|
@ -193,7 +193,7 @@ private:
|
||||||
" std::cout << i << std::endl;\n"
|
" std::cout << i << std::endl;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||||
|
|
||||||
check("class K {};\n"
|
check("class K {};\n"
|
||||||
|
@ -203,7 +203,7 @@ private:
|
||||||
" std::cout << i << std::endl;\n"
|
" std::cout << i << std::endl;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("class K {};\n"
|
check("class K {};\n"
|
||||||
|
@ -213,7 +213,7 @@ private:
|
||||||
" std::cout << i << std::endl;\n"
|
" std::cout << i << std::endl;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||||
|
|
||||||
check("class K {};\n"
|
check("class K {};\n"
|
||||||
|
@ -223,7 +223,7 @@ private:
|
||||||
" std::cout << i << std::endl;\n"
|
" std::cout << i << std::endl;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ private:
|
||||||
" std::cout << k++ << std::endl;\n"
|
" std::cout << k++ << std::endl;\n"
|
||||||
" std::cout << k-- << std::endl;\n"
|
" std::cout << k-- << std::endl;\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("class K {};\n"
|
check("class K {};\n"
|
||||||
|
@ -247,7 +247,7 @@ private:
|
||||||
" std::cout << k << std::endl;\n"
|
" std::cout << k << std::endl;\n"
|
||||||
" std::cout << k-- << std::endl;\n"
|
" std::cout << k-- << std::endl;\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||||
|
|
||||||
check("class K {};\n"
|
check("class K {};\n"
|
||||||
|
@ -258,7 +258,7 @@ private:
|
||||||
" std::cout << ++k << std::endl;\n"
|
" std::cout << ++k << std::endl;\n"
|
||||||
" std::cout << --k << std::endl;\n"
|
" std::cout << --k << std::endl;\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ private:
|
||||||
" k++;\n"
|
" k++;\n"
|
||||||
" std::cout << k << std::endl;\n"
|
" std::cout << k << std::endl;\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
TODO_ASSERT_EQUALS("",
|
TODO_ASSERT_EQUALS("",
|
||||||
"[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
"[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -287,7 +287,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" v.clear();\n"
|
" v.clear();\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||||
|
|
||||||
check("int main() {\n"
|
check("int main() {\n"
|
||||||
|
@ -301,7 +301,7 @@ private:
|
||||||
" it++;\n"
|
" it++;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:9]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:9]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||||
|
|
||||||
check("int main() {\n"
|
check("int main() {\n"
|
||||||
|
@ -314,7 +314,7 @@ private:
|
||||||
" it++;\n"
|
" it++;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||||
|
|
||||||
check("int main() {\n"
|
check("int main() {\n"
|
||||||
|
@ -328,14 +328,14 @@ private:
|
||||||
" rit--;\n"
|
" rit--;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:9]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:9]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test2168() {
|
void test2168() {
|
||||||
check("--> declare allocator lock here\n"
|
check("--> declare allocator lock here\n"
|
||||||
"int main(){}\n");
|
"int main(){}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1319,7 +1319,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" int *n;\n"
|
" int *n;\n"
|
||||||
" sizeof *(n);\n"
|
" sizeof *(n);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5537,7 +5537,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" B * b = new B;\n"
|
" B * b = new B;\n"
|
||||||
" b->f = new A::F * [ 10 ];\n"
|
" b->f = new A::F * [ 10 ];\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
280
test/teststl.cpp
280
test/teststl.cpp
File diff suppressed because it is too large
Load Diff
|
@ -966,7 +966,7 @@ private:
|
||||||
" class X { X(int); };\n"
|
" class X { X(int); };\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"namespace barney { X::X(int) { } }\n");
|
"namespace barney { X::X(int) { } }");
|
||||||
|
|
||||||
// Locate the scope for the class..
|
// Locate the scope for the class..
|
||||||
const Scope *scope = NULL;
|
const Scope *scope = NULL;
|
||||||
|
@ -1000,7 +1000,7 @@ private:
|
||||||
" namespace barney {\n"
|
" namespace barney {\n"
|
||||||
" X::X(int) { }\n"
|
" X::X(int) { }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
|
|
||||||
// Locate the scope for the class..
|
// Locate the scope for the class..
|
||||||
const Scope *scope = NULL;
|
const Scope *scope = NULL;
|
||||||
|
@ -1026,7 +1026,7 @@ private:
|
||||||
|
|
||||||
void namespaces3() { // #3854 - namespace with unknown macro
|
void namespaces3() { // #3854 - namespace with unknown macro
|
||||||
GET_SYMBOL_DB("namespace fred UNKNOWN_MACRO(default) {\n"
|
GET_SYMBOL_DB("namespace fred UNKNOWN_MACRO(default) {\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS(2U, db->scopeList.size());
|
ASSERT_EQUALS(2U, db->scopeList.size());
|
||||||
ASSERT_EQUALS(Scope::eGlobal, db->scopeList.front().type);
|
ASSERT_EQUALS(Scope::eGlobal, db->scopeList.front().type);
|
||||||
ASSERT_EQUALS(Scope::eNamespace, db->scopeList.back().type);
|
ASSERT_EQUALS(Scope::eNamespace, db->scopeList.back().type);
|
||||||
|
@ -1039,7 +1039,7 @@ private:
|
||||||
" catch (const X::Error2 & x) { }\n"
|
" catch (const X::Error2 & x) { }\n"
|
||||||
" catch (Error3 x) { }\n"
|
" catch (Error3 x) { }\n"
|
||||||
" catch (X::Error4 x) { }\n"
|
" catch (X::Error4 x) { }\n"
|
||||||
"}\n");
|
"}");
|
||||||
GET_SYMBOL_DB(str.c_str())
|
GET_SYMBOL_DB(str.c_str())
|
||||||
check(str.c_str(), false);
|
check(str.c_str(), false);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
@ -1077,7 +1077,7 @@ private:
|
||||||
check("typedef void (func_type)();\n"
|
check("typedef void (func_type)();\n"
|
||||||
"struct A {\n"
|
"struct A {\n"
|
||||||
" friend func_type f : 2;\n"
|
" friend func_type f : 2;\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1088,7 +1088,7 @@ private:
|
||||||
"static void function_declaration_after(void) __attribute__((__used__));\n");
|
"static void function_declaration_after(void) __attribute__((__used__));\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("main(int argc, char *argv[]) { }\n");
|
check("main(int argc, char *argv[]) { }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("namespace boost {\n"
|
check("namespace boost {\n"
|
||||||
|
@ -1096,7 +1096,7 @@ private:
|
||||||
" {\n"
|
" {\n"
|
||||||
" return std::locale();\n"
|
" return std::locale();\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("namespace X {\n"
|
check("namespace X {\n"
|
||||||
|
@ -1104,12 +1104,12 @@ private:
|
||||||
" static void function_declaration_before(void) {}\n"
|
" static void function_declaration_before(void) {}\n"
|
||||||
" static void function_declaration_after(void) {}\n"
|
" static void function_declaration_after(void) {}\n"
|
||||||
" static void function_declaration_after(void) __attribute__((__used__));\n"
|
" static void function_declaration_after(void) __attribute__((__used__));\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("testing::testing()\n"
|
check("testing::testing()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1117,7 +1117,7 @@ private:
|
||||||
// ticket #2178 - segmentation fault
|
// ticket #2178 - segmentation fault
|
||||||
check("int CL_INLINE_DECL(integer_decode_float) (int x) {\n"
|
check("int CL_INLINE_DECL(integer_decode_float) (int x) {\n"
|
||||||
" return (sign ? cl_I() : 0);\n"
|
" return (sign ? cl_I() : 0);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1144,7 +1144,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" int f() { return C< ::D,int>::f(); }\n"
|
" int f() { return C< ::D,int>::f(); }\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1157,7 +1157,7 @@ private:
|
||||||
" {\n"
|
" {\n"
|
||||||
" return vcl::unotools::createStandardColorSpace();\n"
|
" return vcl::unotools::createStandardColorSpace();\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n");
|
"};");
|
||||||
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -1184,7 +1184,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"class B {\n"
|
"class B {\n"
|
||||||
" friend void A::f();\n"
|
" friend void A::f();\n"
|
||||||
"};\n");
|
"};");
|
||||||
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -1194,7 +1194,7 @@ private:
|
||||||
check("int g ();\n"
|
check("int g ();\n"
|
||||||
"struct S {\n"
|
"struct S {\n"
|
||||||
" int i : (false ? g () : 1);\n"
|
" int i : (false ? g () : 1);\n"
|
||||||
"};\n");
|
"};");
|
||||||
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -1203,7 +1203,7 @@ private:
|
||||||
// ticket #2547 - segmentation fault
|
// ticket #2547 - segmentation fault
|
||||||
check("class foo {\n"
|
check("class foo {\n"
|
||||||
" void bar2 () = __null;\n"
|
" void bar2 () = __null;\n"
|
||||||
"};\n");
|
"};");
|
||||||
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -1212,7 +1212,7 @@ private:
|
||||||
// ticket #2577 - segmentation fault
|
// ticket #2577 - segmentation fault
|
||||||
check("class foo {\n"
|
check("class foo {\n"
|
||||||
" void bar2 () = A::f;\n"
|
" void bar2 () = A::f;\n"
|
||||||
"};\n");
|
"};");
|
||||||
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -1240,7 +1240,7 @@ private:
|
||||||
|
|
||||||
void symboldatabase17() {
|
void symboldatabase17() {
|
||||||
// ticket #2657 - segmentation fault
|
// ticket #2657 - segmentation fault
|
||||||
check("return f(){}\n");
|
check("return f(){}");
|
||||||
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -1254,7 +1254,7 @@ private:
|
||||||
|
|
||||||
void symboldatabase19() {
|
void symboldatabase19() {
|
||||||
// ticket #2991 - segmentation fault
|
// ticket #2991 - segmentation fault
|
||||||
check("::y(){x}\n");
|
check("::y(){x}");
|
||||||
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -1273,7 +1273,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"Fred::func() const {\n"
|
"Fred::func() const {\n"
|
||||||
" Foo foo;\n"
|
" Foo foo;\n"
|
||||||
"}\n");
|
"}");
|
||||||
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -1287,7 +1287,7 @@ private:
|
||||||
|
|
||||||
// #ticket 3435 (std::vector)
|
// #ticket 3435 (std::vector)
|
||||||
void symboldatabase23() {
|
void symboldatabase23() {
|
||||||
GET_SYMBOL_DB("class A { std::vector<int*> ints; };\n");
|
GET_SYMBOL_DB("class A { std::vector<int*> ints; };");
|
||||||
ASSERT_EQUALS(2U, db->scopeList.size());
|
ASSERT_EQUALS(2U, db->scopeList.size());
|
||||||
const Scope &scope = db->scopeList.back();
|
const Scope &scope = db->scopeList.back();
|
||||||
ASSERT_EQUALS(1U, scope.varlist.size());
|
ASSERT_EQUALS(1U, scope.varlist.size());
|
||||||
|
@ -1367,7 +1367,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" B1()\n"
|
" B1()\n"
|
||||||
" {} C(int) : B1() class\n"
|
" {} C(int) : B1() class\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -78,7 +78,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" if (f1())\n"
|
" if (f1())\n"
|
||||||
" { }\n"
|
" { }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ private:
|
||||||
check("int f1()\n"
|
check("int f1()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" return f1();\n"
|
" return f1();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ private:
|
||||||
check("char * foo()\n"
|
check("char * foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" return *foo();\n"
|
" return *foo();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ private:
|
||||||
check("void f1()\n"
|
check("void f1()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" void (*f)() = cond ? f1 : NULL;\n"
|
" void (*f)() = cond ? f1 : NULL;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" if (cond) ;\n"
|
" if (cond) ;\n"
|
||||||
" else f1();\n"
|
" else f1();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" f(&abc::foo);\n"
|
" f(&abc::foo);\n"
|
||||||
" return 0\n"
|
" return 0\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("namespace abc {\n"
|
check("namespace abc {\n"
|
||||||
|
@ -135,7 +135,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" f = &abc::foo;\n"
|
" f = &abc::foo;\n"
|
||||||
" return 0\n"
|
" return 0\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("namespace abc {\n" // #3875
|
check("namespace abc {\n" // #3875
|
||||||
|
@ -146,7 +146,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" f(abc::foo);\n"
|
" f(abc::foo);\n"
|
||||||
" return 0\n"
|
" return 0\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" foo<int>();\n"
|
" foo<int>();\n"
|
||||||
" return 0\n"
|
" return 0\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,12 +167,12 @@ private:
|
||||||
"template<class T> void g()\n"
|
"template<class T> void g()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" f();\n"
|
" f();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void throwIsNotAFunction() {
|
void throwIsNotAFunction() {
|
||||||
check("struct A {void f() const throw () {}}; int main() {A a; a.f();}\n");
|
check("struct A {void f() const throw () {}}; int main() {A a; a.f();}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,20 +195,20 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void unusedMain() {
|
void unusedMain() {
|
||||||
check("int main() { }\n");
|
check("int main() { }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("int _tmain() { }\n");
|
check("int _tmain() { }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("int WinMain() { }\n");
|
check("int WinMain() { }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void initializationIsNotAFunction() {
|
void initializationIsNotAFunction() {
|
||||||
check("struct B: N::A {\n"
|
check("struct B: N::A {\n"
|
||||||
" B(): N::A() {};\n"
|
" B(): N::A() {};\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ private:
|
||||||
"{ }\n"
|
"{ }\n"
|
||||||
"\n"
|
"\n"
|
||||||
"unsigned int Fred::f()\n"
|
"unsigned int Fred::f()\n"
|
||||||
"{ }\n");
|
"{ }");
|
||||||
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) Unused private function: 'Fred::f'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) Unused private function: 'Fred::f'\n", errout.str());
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ private:
|
||||||
"{ }\n"
|
"{ }\n"
|
||||||
"\n"
|
"\n"
|
||||||
"unsigned int Fred::f()\n"
|
"unsigned int Fred::f()\n"
|
||||||
"{ }\n");
|
"{ }");
|
||||||
|
|
||||||
ASSERT_EQUALS("[p.h:4]: (style) Unused private function: 'Fred::f'\n", errout.str());
|
ASSERT_EQUALS("[p.h:4]: (style) Unused private function: 'Fred::f'\n", errout.str());
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ private:
|
||||||
"\n"
|
"\n"
|
||||||
"void Fred::f()\n"
|
"void Fred::f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[p.h:4]: (style) Unused private function: 'Fred::f'\n", errout.str());
|
ASSERT_EQUALS("[p.h:4]: (style) Unused private function: 'Fred::f'\n", errout.str());
|
||||||
|
|
||||||
// Don't warn about include files which implementation we don't see
|
// Don't warn about include files which implementation we don't see
|
||||||
|
@ -156,7 +156,7 @@ private:
|
||||||
"\n"
|
"\n"
|
||||||
"int main()\n"
|
"int main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"\n"
|
"\n"
|
||||||
"A::A()\n"
|
"A::A()\n"
|
||||||
"{ }\n");
|
"{ }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"\n"
|
"\n"
|
||||||
"A::~A()\n"
|
"A::~A()\n"
|
||||||
"{ B(); }\n");
|
"{ B(); }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"\n"
|
"\n"
|
||||||
"A::A() : _owner(false)\n"
|
"A::A() : _owner(false)\n"
|
||||||
"{ b(); }\n");
|
"{ b(); }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,14 +215,14 @@ private:
|
||||||
" A() : lock(new Lock())\n"
|
" A() : lock(new Lock())\n"
|
||||||
" { }\n"
|
" { }\n"
|
||||||
" Lock *lock;\n"
|
" Lock *lock;\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test6() { // ticket #2602 segmentation fault
|
void test6() { // ticket #2602 segmentation fault
|
||||||
check("class A {\n"
|
check("class A {\n"
|
||||||
" A& operator=(const A&);\n"
|
" A& operator=(const A&);\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Fred::Fred()\n"
|
"Fred::Fred()\n"
|
||||||
"{}\n");
|
"{}");
|
||||||
|
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (style) Unused private function: 'Fred::get'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (style) Unused private function: 'Fred::get'\n", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -268,7 +268,7 @@ private:
|
||||||
" void callback(const& unsigned) const {}\n"
|
" void callback(const& unsigned) const {}\n"
|
||||||
"\n"
|
"\n"
|
||||||
" Observer<UnusedPrivateFunctionMemberPointer, unsigned> mObserver;\n"
|
" Observer<UnusedPrivateFunctionMemberPointer, unsigned> mObserver;\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +282,7 @@ private:
|
||||||
"\n"
|
"\n"
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" void f1() const {}\n"
|
" void f1() const {}\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +296,7 @@ private:
|
||||||
" void (*fptr)();\n"
|
" void (*fptr)();\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"myclass::myclass() { fptr = &f; }\n"
|
"myclass::myclass() { fptr = &f; }\n"
|
||||||
"void myclass::f() {}\n");
|
"void myclass::f() {}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,7 +308,7 @@ private:
|
||||||
" void (*f)();\n"
|
" void (*f)();\n"
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" static void func() { }\n"
|
" static void func() { }\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"\n"
|
"\n"
|
||||||
" int numOfThreads;\n"
|
" int numOfThreads;\n"
|
||||||
"};\n");
|
"};");
|
||||||
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -342,7 +342,7 @@ private:
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" static void f()\n"
|
" static void f()\n"
|
||||||
" { }\n"
|
" { }\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:10]: (style) Unused private function: 'A::f'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:10]: (style) Unused private function: 'A::f'\n", errout.str());
|
||||||
|
|
||||||
check("class A\n"
|
check("class A\n"
|
||||||
|
@ -361,7 +361,7 @@ private:
|
||||||
" B(A *a)\n"
|
" B(A *a)\n"
|
||||||
" { a->f(); }\n"
|
" { a->f(); }\n"
|
||||||
" };\n"
|
" };\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,7 +396,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"#endfile\n"
|
"#endfile\n"
|
||||||
"A::A() { }\n"
|
"A::A() { }\n"
|
||||||
"void A::b() { }\n");
|
"void A::b() { }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -408,7 +408,7 @@ private:
|
||||||
" derived() : base() { }\n"
|
" derived() : base() { }\n"
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" void f();\n"
|
" void f();\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("class base {\n"
|
check("class base {\n"
|
||||||
|
@ -522,7 +522,7 @@ private:
|
||||||
"template <class T>\n"
|
"template <class T>\n"
|
||||||
"T A::getVal() const {\n"
|
"T A::getVal() const {\n"
|
||||||
" return internalGetVal();\n"
|
" return internalGetVal();\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -538,7 +538,7 @@ private:
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" void startListening() {\n"
|
" void startListening() {\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("class Fred\n"
|
check("class Fred\n"
|
||||||
|
@ -550,7 +550,7 @@ private:
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" void startListening() {\n"
|
" void startListening() {\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (style) Unused private function: 'Fred::startListening'\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (style) Unused private function: 'Fred::startListening'\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -649,7 +649,7 @@ private:
|
||||||
"#endfile\n"
|
"#endfile\n"
|
||||||
"void Fred::Init()\n"
|
"void Fred::Init()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
"}\n");
|
"}");
|
||||||
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue