From ff4f8b58f3ef489be3e1b2bafc552f379d4e01d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 28 Sep 2012 18:51:10 +0200 Subject: [PATCH] Disable checkComparisonOfFuncReturningBool check because of false warnings. Ticket #2617 --- lib/checkother.cpp | 9 ++++-- lib/tokenize.cpp | 13 --------- lib/tokenize.h | 8 ------ test/testother.cpp | 68 +++++++++++++++++++++++----------------------- 4 files changed, 41 insertions(+), 57 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index cc54b8b8a..89ed606bf 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2245,6 +2245,11 @@ void CheckOther::misusedScopeObjectError(const Token *tok, const std::string& va void CheckOther::checkComparisonOfFuncReturningBool() { + // FIXME: This checking is "experimental" because of the false positives + // when self checking lib/preprocessor.cpp (#2617) + if (!_settings->experimental) + return; + if (!_settings->isEnabled("style")) return; @@ -2264,7 +2269,7 @@ void CheckOther::checkComparisonOfFuncReturningBool() std::string const first_token_name = first_token->str(); if (first_token->isName()&& isFunction(first_token->str(), _tokenizer->tokens())) { - const Token *fToken = _tokenizer->getFunctionTokenByName(first_token_name.c_str()); + const Token *fToken = NULL; // TODO: locate function token if (fToken &&fToken->previous() && fToken->previous()->str() == "bool") { first_token_func_of_type_bool = true; } @@ -2276,7 +2281,7 @@ void CheckOther::checkComparisonOfFuncReturningBool() } std::string const second_token_name = second_token->str(); if (second_token->isName()&& isFunction(second_token->str(), _tokenizer->tokens())) { - const Token *fToken = _tokenizer->getFunctionTokenByName(second_token_name.c_str()); + const Token *fToken = NULL; // TODO: locate function token if (fToken &&fToken->previous() && fToken->previous()->str() == "bool") { second_token_func_of_type_bool = true; } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 6c779a00d..fd30911e7 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7555,19 +7555,6 @@ bool Tokenizer::IsScopeNoReturn(const Token *endScopeToken, bool *unknown) //--------------------------------------------------------------------------- -const Token *Tokenizer::getFunctionTokenByName(const char funcname[]) const -{ - std::list::const_iterator scope; - - for (scope = _symbolDatabase->scopeList.begin(); scope != _symbolDatabase->scopeList.end(); ++scope) { - if (scope->type == Scope::eFunction) { - if (scope->classDef->str() == funcname) - return scope->classDef; - } - } - return NULL; -} - bool Tokenizer::isFunctionParameterPassedByValue(const Token *fpar) const { // TODO: If symbol database is available, use it. diff --git a/lib/tokenize.h b/lib/tokenize.h index 7387dccf7..daa0fb5d0 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -142,14 +142,6 @@ public: */ unsigned int sizeOfType(const Token *type) const; - /** - * Get function token by function name - * @todo better handling of overloaded functions - * @todo only scan parent scopes - * @param funcname function name - */ - const Token *getFunctionTokenByName(const char funcname[]) const; - /** * Try to determine if function parameter is passed by value by looking * at the function declaration. diff --git a/test/testother.cpp b/test/testother.cpp index 830cd52e4..6eda51c8c 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3992,67 +3992,67 @@ private: " else\n" " return true;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n", "", errout.str()); } void checkComparisonOfFuncReturningBool2() { check("void f(){\n" - " int temp = 4;\n" - " bool a = true;\n" - " if(compare(temp) > a){\n" - " printf(\"foo\");\n" - " }\n" + " int temp = 4;\n" + " bool a = true;\n" + " if(compare(temp) > a){\n" + " printf(\"foo\");\n" + " }\n" "}\n" "bool compare(int temp){\n" - " if(temp==4){\n" - " return true;\n" - " }\n" + " if(temp==4){\n" + " return true;\n" + " }\n" " else\n" - " return false;\n" + " return false;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", "", errout.str()); } void checkComparisonOfFuncReturningBool3() { check("void f(){\n" - " int temp = 4;\n" - " if(compare(temp) > temp){\n" - " printf(\"foo\");\n" + " int temp = 4;\n" + " if(compare(temp) > temp){\n" + " printf(\"foo\");\n" " }\n" "}\n" "bool compare(int temp){\n" " if(temp==4){\n" - " return true;\n" + " return true;\n" " }\n" - " else\n" - " return false;\n" + " else\n" + " return false;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", "", errout.str()); } void checkComparisonOfFuncReturningBool4() { check("void f(){\n" " int temp = 4;\n" - " bool b = compare2(6);\n" - " if(compare1(temp)> b){\n" - " printf(\"foo\");\n" - " }\n" + " bool b = compare2(6);\n" + " if(compare1(temp)> b){\n" + " printf(\"foo\");\n" + " }\n" "}\n" "bool compare1(int temp){\n" - " if(temp==4){\n" - " return true;\n" - " }\n" - " else\n" - " return false;\n" + " if(temp==4){\n" + " return true;\n" + " }\n" + " else\n" + " return false;\n" "}\n" "bool compare2(int temp){\n" - " if(temp == 5){\n" - " return true;\n" - " }\n" - " else\n" - " return false;\n" + " if(temp == 5){\n" + " return true;\n" + " }\n" + " else\n" + " return false;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", "", errout.str()); } void checkComparisonOfFuncReturningBool5() { @@ -4076,7 +4076,7 @@ private: " else\n" " return true;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n", "", errout.str()); } void checkComparisonOfBoolWithBool() {