Self assignment in class: added TODO test cases to reduce false positives
This commit is contained in:
parent
12641e2d76
commit
774e331dea
|
@ -306,6 +306,21 @@ private:
|
||||||
" A & operator=(const A &a) { return *this; }\n"
|
" A & operator=(const A &a) { return *this; }\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (possible style) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (possible style) 'operator=' should check for assignment to self\n", errout.str());
|
||||||
|
TODO_ASSERT_EQUALS("", errout.str()); // No reason to check for self-assignment in this class
|
||||||
|
|
||||||
|
checkOpertorEqToSelf(
|
||||||
|
"class A\n"
|
||||||
|
"{\n"
|
||||||
|
"public:\n"
|
||||||
|
" char *s;\n"
|
||||||
|
" A & operator=(const A &a)\n"
|
||||||
|
" {\n"
|
||||||
|
" free(s);\n"
|
||||||
|
" s = strdup(a.s);\n"
|
||||||
|
" return *this;\n"
|
||||||
|
" }\n"
|
||||||
|
"};\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:5]: (possible style) 'operator=' should check for assignment to self\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqToSelf(
|
checkOpertorEqToSelf(
|
||||||
"class A\n"
|
"class A\n"
|
||||||
|
@ -333,6 +348,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"A & A::operator=(const A &a) { return *this; }\n");
|
"A & A::operator=(const A &a) { return *this; }\n");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (possible style) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (possible style) 'operator=' should check for assignment to self\n", errout.str());
|
||||||
|
TODO_ASSERT_EQUALS("", errout.str()); // No reason to check for self-assignment in this class
|
||||||
|
|
||||||
checkOpertorEqToSelf(
|
checkOpertorEqToSelf(
|
||||||
"class A\n"
|
"class A\n"
|
||||||
|
@ -342,6 +358,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"A & A::operator=(const A &a) { return *this; }\n");
|
"A & A::operator=(const A &a) { return *this; }\n");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (possible style) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (possible style) 'operator=' should check for assignment to self\n", errout.str());
|
||||||
|
TODO_ASSERT_EQUALS("", errout.str()); // No reason to check for self-assignment in this class
|
||||||
|
|
||||||
checkOpertorEqToSelf(
|
checkOpertorEqToSelf(
|
||||||
"class A\n"
|
"class A\n"
|
||||||
|
@ -366,6 +383,7 @@ private:
|
||||||
" };\n"
|
" };\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (possible style) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (possible style) 'operator=' should check for assignment to self\n", errout.str());
|
||||||
|
TODO_ASSERT_EQUALS("", errout.str()); // No reason to check for self-assignment in this class
|
||||||
|
|
||||||
checkOpertorEqToSelf(
|
checkOpertorEqToSelf(
|
||||||
"class A\n"
|
"class A\n"
|
||||||
|
@ -392,6 +410,7 @@ private:
|
||||||
"};\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; }\n");
|
||||||
ASSERT_EQUALS("[test.cpp:10]: (possible style) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:10]: (possible style) 'operator=' should check for assignment to self\n", errout.str());
|
||||||
|
TODO_ASSERT_EQUALS("", errout.str()); // No reason to check for self-assignment in this class
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that base classes have virtual destructors
|
// Check that base classes have virtual destructors
|
||||||
|
|
Loading…
Reference in New Issue