From 84c3ec9c4cadb13bfa4c144ea5c7454b9cdb9361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 10 May 2010 21:22:59 +0200 Subject: [PATCH] Fixed #1669 (Still seeing 'possible style' warnings in 1.43) --- lib/checkclass.cpp | 6 +++--- test/testclass.cpp | 21 +++++++++++++-------- test/testconstructors.cpp | 6 +++--- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 1acef8bbc..a2814a5cc 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1216,7 +1216,7 @@ static bool hasMultipleInheritanceGlobal(const Token * start, const std::string void CheckClass::operatorEqToSelf() { - if (!_settings->_checkCodingStyle || !_settings->inconclusive) + if (!_settings->_checkCodingStyle) return; const Token *tok2 = _tokenizer->tokens(); @@ -1994,7 +1994,7 @@ void CheckClass::uninitVarError(const Token *tok, const std::string &classname, void CheckClass::operatorEqVarError(const Token *tok, const std::string &classname, const std::string &varname) { - reportError(tok, Severity::possibleStyle, "operatorEqVarError", "Member variable '" + classname + "::" + varname + "' is not assigned a value in '" + classname + "::operator=" + "'"); + reportError(tok, Severity::style, "operatorEqVarError", "Member variable '" + classname + "::" + varname + "' is not assigned a value in '" + classname + "::operator=" + "'"); } void CheckClass::unusedPrivateFunctionError(const Token *tok, const std::string &classname, const std::string &funcname) @@ -2029,5 +2029,5 @@ void CheckClass::operatorEqRetRefThisError(const Token *tok) void CheckClass::operatorEqToSelfError(const Token *tok) { - reportError(tok, Severity::possibleStyle, "operatorEqToSelf", "'operator=' should check for assignment to self"); + reportError(tok, Severity::style, "operatorEqToSelf", "'operator=' should check for assignment to self"); } diff --git a/test/testclass.cpp b/test/testclass.cpp index 53eec6b55..a7fd3277b 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -479,7 +479,7 @@ private: " return *this;\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:5]: (possible style) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (style) 'operator=' should check for assignment to self\n", errout.str()); // this test has an assignment test but doesn't need it checkOpertorEqToSelf( @@ -534,7 +534,7 @@ private: " s = strdup(a.s);\n" " return *this;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (possible style) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (style) 'operator=' should check for assignment to self\n", errout.str()); // ticket #1224 checkOpertorEqToSelf( @@ -621,7 +621,7 @@ private: " }\n" " };\n" "};\n"); - ASSERT_EQUALS("[test.cpp:8]: (possible style) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should check for assignment to self\n", errout.str()); // this test has an assignment test but doesn't need it checkOpertorEqToSelf( @@ -692,7 +692,7 @@ private: " s = strdup(b.s);\n" " return *this;\n" " }\n"); - ASSERT_EQUALS("[test.cpp:11]: (possible style) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:11]: (style) 'operator=' should check for assignment to self\n", errout.str()); } void operatorEqToSelf3() @@ -1118,7 +1118,7 @@ private: "private:\n" " char * data;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (possible style) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (style) 'operator=' should check for assignment to self\n", errout.str()); checkOpertorEqToSelf( "class A\n" @@ -1135,7 +1135,7 @@ private: " strcpy(data, a.data);\n" " return *this;\n" "};"); - ASSERT_EQUALS("[test.cpp:8]: (possible style) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should check for assignment to self\n", errout.str()); checkOpertorEqToSelf( "class A\n" @@ -1151,7 +1151,7 @@ private: "private:\n" " char * data;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (possible style) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (style) 'operator=' should check for assignment to self\n", errout.str()); checkOpertorEqToSelf( "class A\n" @@ -1168,7 +1168,7 @@ private: " *data = *a.data;\n" " return *this;\n" "};"); - ASSERT_EQUALS("[test.cpp:8]: (possible style) 'operator=' should check for assignment to self\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should check for assignment to self\n", errout.str()); } // Check that base classes have virtual destructors @@ -1763,8 +1763,13 @@ private: " Foo(int _i) { }\n" "};\n"); + // actual results - "possible style" for both messages ASSERT_EQUALS("[test.cpp:5]: (possible style) Member variable not initialized in the constructor 'Foo::foo'\n" "[test.cpp:7]: (possible style) Member variable not initialized in the constructor 'Foo::foo'\n", errout.str()); + + // wanted results - "style" for the public constructor + TODO_ASSERT_EQUALS("[test.cpp:5]: (possible style) Member variable not initialized in the constructor 'Foo::foo'\n" + "[test.cpp:7]: (style) Member variable not initialized in the constructor 'Foo::foo'\n", errout.str()); } diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 706f9268f..92a31aa07 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -390,7 +390,7 @@ private: " void operator=(const Fred &fred) { }\n" " int i;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:5]: (possible style) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (style) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n", errout.str()); check("struct Fred\n" "{\n" @@ -398,7 +398,7 @@ private: " void operator=(const Fred &fred) { }\n" " int i;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (possible style) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (style) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n", errout.str()); } void initvar_operator_eq3() @@ -706,7 +706,7 @@ private: "\n" "void Fred::operator=(const Fred &f)\n" "{ }", true); - ASSERT_EQUALS("[test.cpp:13]: (possible style) Member variable 'Fred::ints' is not assigned a value in 'Fred::operator='\n", errout.str()); + ASSERT_EQUALS("[test.cpp:13]: (style) Member variable 'Fred::ints' is not assigned a value in 'Fred::operator='\n", errout.str()); } };