From 774e331dea4bcbd60e3363c9804df1cb302bda18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 31 Dec 2009 14:03:35 +0100 Subject: [PATCH] Self assignment in class: added TODO test cases to reduce false positives --- test/testclass.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/testclass.cpp b/test/testclass.cpp index 0a7cf7862..4022ed0ba 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -306,6 +306,21 @@ private: " A & operator=(const A &a) { return *this; }\n" "};\n"); 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( "class A\n" @@ -333,6 +348,7 @@ private: "};\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()); + TODO_ASSERT_EQUALS("", errout.str()); // No reason to check for self-assignment in this class checkOpertorEqToSelf( "class A\n" @@ -342,6 +358,7 @@ private: "};\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()); + TODO_ASSERT_EQUALS("", errout.str()); // No reason to check for self-assignment in this class checkOpertorEqToSelf( "class A\n" @@ -366,6 +383,7 @@ private: " };\n" "};\n"); 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( "class A\n" @@ -392,6 +410,7 @@ private: "};\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()); + TODO_ASSERT_EQUALS("", errout.str()); // No reason to check for self-assignment in this class } // Check that base classes have virtual destructors