diff --git a/lib/check.h b/lib/check.h index 054eaed6a..8aca4ca95 100644 --- a/lib/check.h +++ b/lib/check.h @@ -101,7 +101,7 @@ protected: std::list callstack; if (tok) callstack.push_back(tok); - else if (severity == Severity::possibleError || severity == Severity::possibleStyle) + else if (severity == Severity::possibleError) return; // don't list inconclusive checks in the --errorlist output reportError(callstack, severity, id, msg); } diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 8862ffa63..91c065751 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -582,8 +582,8 @@ void CheckClass::checkConstructors(const Token *tok1, const std::string &funcnam if (classNameUsed) operatorEqVarError(constructor_token, className, var->name); } - else if (!var->isStatic) - uninitVarError(constructor_token, className, var->name, hasPrivateConstructor); + else if (!hasPrivateConstructor && !var->isStatic) + uninitVarError(constructor_token, className, var->name); } for (Var *var = varlist; var; var = var->next) @@ -1986,9 +1986,9 @@ void CheckClass::noConstructorError(const Token *tok, const std::string &classna reportError(tok, Severity::style, "noConstructor", "The " + std::string(isStruct ? "struct" : "class") + " '" + classname + "' has no constructor. Member variables not initialized."); } -void CheckClass::uninitVarError(const Token *tok, const std::string &classname, const std::string &varname, bool hasPrivateConstructor) +void CheckClass::uninitVarError(const Token *tok, const std::string &classname, const std::string &varname) { - reportError(tok, hasPrivateConstructor ? Severity::possibleStyle : Severity::style, "uninitVar", "Member variable not initialized in the constructor '" + classname + "::" + varname + "'"); + reportError(tok, Severity::style, "uninitVar", "Member variable not initialized in the constructor '" + classname + "::" + varname + "'"); } void CheckClass::operatorEqVarError(const Token *tok, const std::string &classname, const std::string &varname) diff --git a/lib/checkclass.h b/lib/checkclass.h index 5d4e83309..318fa2b60 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -180,7 +180,7 @@ private: // Reporting errors.. void noConstructorError(const Token *tok, const std::string &classname, bool isStruct); - void uninitVarError(const Token *tok, const std::string &classname, const std::string &varname, bool hasPrivateConstructor); + void uninitVarError(const Token *tok, const std::string &classname, const std::string &varname); void operatorEqVarError(const Token *tok, const std::string &classname, const std::string &varname); void unusedPrivateFunctionError(const Token *tok, const std::string &classname, const std::string &funcname); void memsetClassError(const Token *tok, const std::string &memfunc); @@ -197,7 +197,7 @@ private: void getErrorMessages() { noConstructorError(0, "classname", false); - uninitVarError(0, "classname", "varname", false); + uninitVarError(0, "classname", "varname"); operatorEqVarError(0, "classname", ""); unusedPrivateFunctionError(0, "classname", "funcname"); memsetClassError(0, "memfunc"); diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 3676f60fa..0e9366673 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -356,7 +356,7 @@ void CheckOther::invalidFunctionUsage() void CheckOther::checkUnsignedDivision() { - if (!_settings->inconclusive || !_settings->_checkCodingStyle) + if (!_settings->_checkCodingStyle) return; // Check for "ivar / uvar" and "uvar / ivar" @@ -371,24 +371,9 @@ void CheckOther::checkUnsignedDivision() varsign[tok->tokAt(2)->varId()] = 's'; } - else if (!Token::Match(tok, "[).]") && - Token::Match(tok->next(), "%var% / %var%") && - tok->tokAt(1)->varId() != 0 && - tok->tokAt(3)->varId() != 0) - { - char sign1 = varsign[tok->tokAt(1)->varId()]; - char sign2 = varsign[tok->tokAt(3)->varId()]; - - if (sign1 && sign2 && sign1 != sign2) - { - // One of the operands are signed, the other is unsigned.. - udivWarning(tok->next()); - } - } - else if (!Token::Match(tok, "[).]") && Token::Match(tok->next(), "%var% / %num%")) { - if (tok->strAt(3)[0] == '-' && ErrorLogger::udivError()) + if (tok->strAt(3)[0] == '-') { char sign1 = varsign[tok->tokAt(1)->varId()]; if (sign1 == 'u') @@ -400,7 +385,7 @@ void CheckOther::checkUnsignedDivision() else if (Token::Match(tok, "[([=*/+-,] %num% / %var%")) { - if (tok->strAt(1)[0] == '-' && ErrorLogger::udivError()) + if (tok->strAt(1)[0] == '-') { char sign2 = varsign[tok->tokAt(3)->varId()]; if (sign2 == 'u') @@ -3518,11 +3503,6 @@ void CheckOther::udivError(const Token *tok) reportError(tok, Severity::error, "udivError", "Unsigned division. The result will be wrong."); } -void CheckOther::udivWarning(const Token *tok) -{ - reportError(tok, Severity::possibleStyle, "udivWarning", "Division with signed and unsigned operators"); -} - void CheckOther::unusedStructMemberError(const Token *tok, const std::string &structname, const std::string &varname) { reportError(tok, Severity::style, "unusedStructMember", "struct or union member '" + structname + "::" + varname + "' is never used"); @@ -3614,7 +3594,7 @@ void CheckOther::mathfunctionCallError(const Token *tok, const unsigned int numP void CheckOther::postIncrementError(const Token *tok, const std::string &var_name, const bool isIncrement) { std::string type = (isIncrement ? "Incrementing" : "Decrementing"); - reportError(tok, Severity::possibleStyle, "postIncrementDecrement", ("Pre-" + type + " variable '" + var_name + "' is preferred to Post-" + type)); + reportError(tok, Severity::style, "postIncrementDecrement", ("Pre-" + type + " variable '" + var_name + "' is preferred to Post-" + type)); } void CheckOther::emptyStringTestError(const Token *tok, const std::string &var_name, const bool isTestForEmpty) diff --git a/lib/checkother.h b/lib/checkother.h index 0a1208206..5af1c3d66 100644 --- a/lib/checkother.h +++ b/lib/checkother.h @@ -174,7 +174,6 @@ public: void dangerousUsageStrtolError(const Token *tok); void sprintfOverlappingDataError(const Token *tok, const std::string &varname); void udivError(const Token *tok); - void udivWarning(const Token *tok); void unusedStructMemberError(const Token *tok, const std::string &structname, const std::string &varname); void passedByValueError(const Token *tok, const std::string &parname); void constStatementError(const Token *tok, const std::string &type); @@ -213,7 +212,6 @@ public: redundantIfDelete0Error(0); redundantIfRemoveError(0); dangerousUsageStrtolError(0); - udivWarning(0); unusedStructMemberError(0, "structname", "variable"); passedByValueError(0, "parametername"); constStatementError(0, "type"); diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index f8b1ffa68..5a0f4d7a9 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -688,5 +688,5 @@ void CheckStl::sizeError(const Token *tok) { const std::string varname(tok ? tok->str().c_str() : "list"); const bool verbose(_settings ? _settings->_verbose : true); - reportError(tok, Severity::possibleStyle, "stlSize", "Use " + varname + ".empty() instead of " + varname + ".size() to guarantee fast code." + (verbose ? " size() can take linear time but empty() is guaranteed to take constant time." : "")); + reportError(tok, Severity::style, "stlSize", "Use " + varname + ".empty() instead of " + varname + ".size() to guarantee fast code." + (verbose ? " size() can take linear time but empty() is guaranteed to take constant time." : "")); } diff --git a/lib/errorlogger.h b/lib/errorlogger.h index 6a8913447..018865d43 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -322,7 +322,7 @@ private: class Severity { public: - enum e { error, style, possibleError, possibleStyle }; + enum e { error, style, possibleError }; static std::string stringify(e severity) { switch (severity) @@ -333,8 +333,6 @@ public: return "style"; case possibleError: return "possible error"; - case possibleStyle: - return "possible style"; }; return "???"; } diff --git a/test/testclass.cpp b/test/testclass.cpp index d93c5d0a2..fb947f758 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -1762,8 +1762,7 @@ private: " int foo;\n" " Foo() { }\n" "};\n"); - - ASSERT_EQUALS("[test.cpp:3]: (possible style) Member variable not initialized in the constructor 'Foo::foo'\n", errout.str()); + ASSERT_EQUALS("", errout.str()); } void privateCtor2() @@ -1777,13 +1776,11 @@ 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()); + // actual results + ASSERT_EQUALS("", 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()); + // wanted results - warning for the public constructor + TODO_ASSERT_EQUALS("[test.cpp:7]: (style) Member variable not initialized in the constructor 'Foo::foo'\n", errout.str()); } diff --git a/test/testdivision.cpp b/test/testdivision.cpp index a6fe278af..c58d4202c 100644 --- a/test/testdivision.cpp +++ b/test/testdivision.cpp @@ -36,7 +36,7 @@ public: { } private: - void check(const char code[], bool style = true, bool all = true) + void check(const char code[], bool style = true) { // Tokenize.. Tokenizer tokenizer; @@ -47,7 +47,6 @@ private: errout.str(""); Settings settings; - settings.inconclusive = all; settings._checkCodingStyle = style; // Check for unsigned divisions.. @@ -59,7 +58,6 @@ private: { TEST_CASE(division1); TEST_CASE(division2); - TEST_CASE(division3); TEST_CASE(division4); TEST_CASE(division5); TEST_CASE(division6); @@ -76,7 +74,8 @@ private: " unsigned int uvar = 2;\n" " return ivar / uvar;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (possible style) Division with signed and unsigned operators\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Division with signed and unsigned operators\n", errout.str()); + ASSERT_EQUALS("", errout.str()); } void division2() @@ -87,20 +86,8 @@ private: " unsigned int uvar = 2;\n" " return uvar / ivar;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (possible style) Division with signed and unsigned operators\n", errout.str()); - } - - void division3() - { - check("typedef int s32;\n" - "typedef unsigned int u32;\n" - "void f()\n" - "{\n" - " s32 ivar = -2;\n" - " u32 uvar = 2;\n" - " return uvar / ivar;\n" - "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (possible style) Division with signed and unsigned operators\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Division with signed and unsigned operators\n", errout.str()); + ASSERT_EQUALS("", errout.str()); } void division4() @@ -155,8 +142,7 @@ private: check("void foo()\n" "{\n" " unsigned int val = 32;\n" - " int i = -96 / val; }\n" - ); + " int i = -96 / val; }\n"); ASSERT_EQUALS("[test.cpp:4]: (error) Unsigned division. The result will be wrong.\n", errout.str()); } @@ -169,35 +155,26 @@ private: " unsigned int a;\n" " unsigned int c = a / b;\n" " }\n" - "}\n", false, true); + "}\n", true); ASSERT_EQUALS("", errout.str()); check("void foo(int b)\n" "{\n" - " if (b > 0)\n" + " if (b < 0)\n" " {\n" " unsigned int a;\n" " unsigned int c = a / b;\n" " }\n" - "}\n", true, false); + "}\n", true); ASSERT_EQUALS("", errout.str()); - - check("void foo(int b)\n" - "{\n" - " if (b > 0)\n" - " {\n" - " unsigned int a;\n" - " unsigned int c = a / b;\n" - " }\n" - "}\n", true, true); - ASSERT_EQUALS("[test.cpp:6]: (possible style) Division with signed and unsigned operators\n", errout.str()); + TODO_ASSERT_EQUALS("unsigned division", errout.str()); check("void a(int i) { }\n" "int foo( unsigned int sz )\n" "{\n" " register unsigned int i=1;\n" " return i/sz;\n" - "}\n", true, true); + "}\n", true); ASSERT_EQUALS("", errout.str()); } @@ -209,7 +186,8 @@ private: " unsigned long uvar = 2;\n" " return ivar / uvar;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (possible style) Division with signed and unsigned operators\n", errout.str()); + ASSERT_EQUALS("", errout.str()); + TODO_ASSERT_EQUALS("unsigned division", errout.str()); check("void f()\n" "{\n" @@ -217,20 +195,8 @@ private: " unsigned long long uvar = 2;\n" " return ivar / uvar;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (possible style) Division with signed and unsigned operators\n", errout.str()); - - check("template class C\n" - "{\n" - " A a;\n" - " B b;\n" - " void foo() { a / b; }\n" - "};\n" - "C c1;\n" - "C c2;\n" - "C c3;\n"); - ASSERT_EQUALS("[test.cpp:5]: (possible style) Division with signed and unsigned operators\n" - "[test.cpp:5]: (possible style) Division with signed and unsigned operators\n" - "[test.cpp:5]: (possible style) Division with signed and unsigned operators\n", errout.str()); + ASSERT_EQUALS("", errout.str()); + TODO_ASSERT_EQUALS("unsigned division", errout.str()); } }; diff --git a/test/testother.cpp b/test/testother.cpp index 03dedb934..deaa46e5c 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2150,7 +2150,7 @@ private: " for (it = ab.begin(); it != ab.end(); it++)\n" " ;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str()); checkpostIncrementDecrement("void f1()\n" "{\n" @@ -2160,8 +2160,8 @@ private: " for (it = ab.begin(); it != ab.end(); it++)\n" " ;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n" - "[test.cpp:6]: (possible style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n" + "[test.cpp:6]: (style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str()); checkpostIncrementDecrement("void f2()\n" "{\n" @@ -2169,7 +2169,7 @@ private: " for (it = ab.end(); it != ab.begin(); it--)\n" " ;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Decrementing variable 'it' is preferred to Post-Decrementing\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (style) Pre-Decrementing variable 'it' is preferred to Post-Decrementing\n", errout.str()); checkpostIncrementDecrement("void f2()\n" "{\n" @@ -2179,8 +2179,8 @@ private: " for (it = ab.end(); it != ab.begin(); it--)\n" " ;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Decrementing variable 'it' is preferred to Post-Decrementing\n" - "[test.cpp:6]: (possible style) Pre-Decrementing variable 'it' is preferred to Post-Decrementing\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (style) Pre-Decrementing variable 'it' is preferred to Post-Decrementing\n" + "[test.cpp:6]: (style) Pre-Decrementing variable 'it' is preferred to Post-Decrementing\n", errout.str()); checkpostIncrementDecrement("void f1()\n" "{\n" @@ -2188,7 +2188,7 @@ private: " for (it = ab.begin(); it != ab.end(); it++)\n" " ;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str()); checkpostIncrementDecrement("void f1()\n" "{\n" @@ -2196,7 +2196,7 @@ private: " for (it = ab.begin(); it != ab.end(); it++)\n" " ;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str()); } void postIncrementDecrementClass() @@ -2208,7 +2208,7 @@ private: " for (tClass = TestClass.begin(); tClass != TestClass.end(); tClass++)\n" " ;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (possible style) Pre-Incrementing variable 'tClass' is preferred to Post-Incrementing\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (style) Pre-Incrementing variable 'tClass' is preferred to Post-Incrementing\n", errout.str()); checkpostIncrementDecrement("class TestClass;\n" "void f1()\n" @@ -2217,7 +2217,7 @@ private: " for (tClass = TestClass.end(); tClass != TestClass.begin(); tClass--)\n" " ;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (possible style) Pre-Decrementing variable 'tClass' is preferred to Post-Decrementing\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (style) Pre-Decrementing variable 'tClass' is preferred to Post-Decrementing\n", errout.str()); } void dangerousStrolUsage() diff --git a/test/teststl.cpp b/test/teststl.cpp index 5671f307f..af80a1a1d 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -819,28 +819,28 @@ private: " std::list x;\n" " if (x.size() == 0) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (possible style) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (style) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " if (x.size() != 0) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (possible style) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (style) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " if (x.size() > 0) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (possible style) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (style) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " if (x.size()) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (possible style) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (style) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str()); check("void f()\n" "{\n"