Disable checkComparisonOfFuncReturningBool check because of false warnings. Ticket #2617
This commit is contained in:
parent
bb62325ddb
commit
ff4f8b58f3
|
@ -2245,6 +2245,11 @@ void CheckOther::misusedScopeObjectError(const Token *tok, const std::string& va
|
||||||
|
|
||||||
void CheckOther::checkComparisonOfFuncReturningBool()
|
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"))
|
if (!_settings->isEnabled("style"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -2264,7 +2269,7 @@ void CheckOther::checkComparisonOfFuncReturningBool()
|
||||||
|
|
||||||
std::string const first_token_name = first_token->str();
|
std::string const first_token_name = first_token->str();
|
||||||
if (first_token->isName()&& isFunction(first_token->str(), _tokenizer->tokens())) {
|
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") {
|
if (fToken &&fToken->previous() && fToken->previous()->str() == "bool") {
|
||||||
first_token_func_of_type_bool = true;
|
first_token_func_of_type_bool = true;
|
||||||
}
|
}
|
||||||
|
@ -2276,7 +2281,7 @@ void CheckOther::checkComparisonOfFuncReturningBool()
|
||||||
}
|
}
|
||||||
std::string const second_token_name = second_token->str();
|
std::string const second_token_name = second_token->str();
|
||||||
if (second_token->isName()&& isFunction(second_token->str(), _tokenizer->tokens())) {
|
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") {
|
if (fToken &&fToken->previous() && fToken->previous()->str() == "bool") {
|
||||||
second_token_func_of_type_bool = true;
|
second_token_func_of_type_bool = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7555,19 +7555,6 @@ bool Tokenizer::IsScopeNoReturn(const Token *endScopeToken, bool *unknown)
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
const Token *Tokenizer::getFunctionTokenByName(const char funcname[]) const
|
|
||||||
{
|
|
||||||
std::list<Scope>::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
|
bool Tokenizer::isFunctionParameterPassedByValue(const Token *fpar) const
|
||||||
{
|
{
|
||||||
// TODO: If symbol database is available, use it.
|
// TODO: If symbol database is available, use it.
|
||||||
|
|
|
@ -142,14 +142,6 @@ public:
|
||||||
*/
|
*/
|
||||||
unsigned int sizeOfType(const Token *type) const;
|
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
|
* Try to determine if function parameter is passed by value by looking
|
||||||
* at the function declaration.
|
* at the function declaration.
|
||||||
|
|
|
@ -3992,67 +3992,67 @@ private:
|
||||||
" else\n"
|
" else\n"
|
||||||
" return true;\n"
|
" return true;\n"
|
||||||
"}\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() {
|
void checkComparisonOfFuncReturningBool2() {
|
||||||
check("void f(){\n"
|
check("void f(){\n"
|
||||||
" int temp = 4;\n"
|
" int temp = 4;\n"
|
||||||
" bool a = true;\n"
|
" bool a = true;\n"
|
||||||
" if(compare(temp) > a){\n"
|
" if(compare(temp) > a){\n"
|
||||||
" printf(\"foo\");\n"
|
" printf(\"foo\");\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"bool compare(int temp){\n"
|
"bool compare(int temp){\n"
|
||||||
" if(temp==4){\n"
|
" if(temp==4){\n"
|
||||||
" return true;\n"
|
" return true;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" else\n"
|
" else\n"
|
||||||
" return false;\n"
|
" return false;\n"
|
||||||
"}\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() {
|
void checkComparisonOfFuncReturningBool3() {
|
||||||
check("void f(){\n"
|
check("void f(){\n"
|
||||||
" int temp = 4;\n"
|
" int temp = 4;\n"
|
||||||
" if(compare(temp) > temp){\n"
|
" if(compare(temp) > temp){\n"
|
||||||
" printf(\"foo\");\n"
|
" printf(\"foo\");\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"bool compare(int temp){\n"
|
"bool compare(int temp){\n"
|
||||||
" if(temp==4){\n"
|
" if(temp==4){\n"
|
||||||
" return true;\n"
|
" return true;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" else\n"
|
" else\n"
|
||||||
" return false;\n"
|
" return false;\n"
|
||||||
"}\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() {
|
void checkComparisonOfFuncReturningBool4() {
|
||||||
check("void f(){\n"
|
check("void f(){\n"
|
||||||
" int temp = 4;\n"
|
" int temp = 4;\n"
|
||||||
" bool b = compare2(6);\n"
|
" bool b = compare2(6);\n"
|
||||||
" if(compare1(temp)> b){\n"
|
" if(compare1(temp)> b){\n"
|
||||||
" printf(\"foo\");\n"
|
" printf(\"foo\");\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"bool compare1(int temp){\n"
|
"bool compare1(int temp){\n"
|
||||||
" if(temp==4){\n"
|
" if(temp==4){\n"
|
||||||
" return true;\n"
|
" return true;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" else\n"
|
" else\n"
|
||||||
" return false;\n"
|
" return false;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"bool compare2(int temp){\n"
|
"bool compare2(int temp){\n"
|
||||||
" if(temp == 5){\n"
|
" if(temp == 5){\n"
|
||||||
" return true;\n"
|
" return true;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" else\n"
|
" else\n"
|
||||||
" return false;\n"
|
" return false;\n"
|
||||||
"}\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() {
|
void checkComparisonOfFuncReturningBool5() {
|
||||||
|
@ -4076,7 +4076,7 @@ private:
|
||||||
" else\n"
|
" else\n"
|
||||||
" return true;\n"
|
" return true;\n"
|
||||||
"}\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() {
|
void checkComparisonOfBoolWithBool() {
|
||||||
|
|
Loading…
Reference in New Issue