CheckBool: Skip 'bool' type checking in C code
This commit is contained in:
parent
b81de5494e
commit
f9cf148012
|
@ -119,7 +119,7 @@ static bool isNonBoolStdType(const Variable* var)
|
||||||
}
|
}
|
||||||
void CheckBool::checkComparisonOfBoolWithInt()
|
void CheckBool::checkComparisonOfBoolWithInt()
|
||||||
{
|
{
|
||||||
if (!_settings->isEnabled("warning"))
|
if (!_settings->isEnabled("warning") || !_tokenizer->isCPP())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase();
|
const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||||
|
|
|
@ -58,7 +58,7 @@ private:
|
||||||
TEST_CASE(checkComparisonOfFuncReturningBool6);
|
TEST_CASE(checkComparisonOfFuncReturningBool6);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[], bool experimental = false) {
|
void check(const char code[], bool experimental = false, const char filename[] = "test.cpp") {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
tokenizer.tokenize(istr, filename);
|
||||||
|
|
||||||
// Check...
|
// Check...
|
||||||
CheckBool checkBool(&tokenizer, &settings, this);
|
CheckBool checkBool(&tokenizer, &settings, this);
|
||||||
|
@ -312,6 +312,16 @@ private:
|
||||||
|
|
||||||
check("int f() { return (!a+b<c); }");
|
check("int f() { return (!a+b<c); }");
|
||||||
ASSERT_EQUALS("",errout.str());
|
ASSERT_EQUALS("",errout.str());
|
||||||
|
|
||||||
|
{
|
||||||
|
const char code[] = "void f(int x, bool y) { if ( x != y ) {} }";
|
||||||
|
|
||||||
|
check(code, false, "test.cpp");
|
||||||
|
ASSERT_EQUALS("[test.cpp:1]: (warning) Comparison of a boolean with an integer.\n", errout.str());
|
||||||
|
|
||||||
|
check(code, false, "test.c");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void comparisonOfBoolExpressionWithInt2() {
|
void comparisonOfBoolExpressionWithInt2() {
|
||||||
|
|
Loading…
Reference in New Issue