Following the discussion XX, replace the keyword C99 '_Bool' with the 'bool' keyword in the process of tokenization\nSee f29b7f9f08
This commit is contained in:
parent
46b5d5bd00
commit
5c7ed46e0c
|
@ -237,7 +237,7 @@ void CheckOther::checkBitwiseOnBoolean()
|
||||||
{
|
{
|
||||||
const Variable *var = _tokenizer->getSymbolDatabase()->getVariableFromVarId(tok->next()->varId());
|
const Variable *var = _tokenizer->getSymbolDatabase()->getVariableFromVarId(tok->next()->varId());
|
||||||
if (var && (var->typeStartToken() == var->typeEndToken()) &&
|
if (var && (var->typeStartToken() == var->typeEndToken()) &&
|
||||||
Token::Match(var->typeStartToken(), "bool|_Bool"))
|
var->typeStartToken()->str() == "bool")
|
||||||
{
|
{
|
||||||
bitwiseOnBooleanError(tok->next(), tok->next()->str(), tok->strAt(2) == "&" ? "&&" : "||");
|
bitwiseOnBooleanError(tok->next(), tok->next()->str(), tok->strAt(2) == "&" ? "&&" : "||");
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,6 +145,10 @@ void Tokenizer::addtoken(const char str[], const unsigned int lineno, const unsi
|
||||||
{
|
{
|
||||||
str2 << std::strtoul(str + 2, NULL, 16);
|
str2 << std::strtoul(str + 2, NULL, 16);
|
||||||
}
|
}
|
||||||
|
else if (strncmp(str, "_Bool", 5) == 0)
|
||||||
|
{
|
||||||
|
str2 << "bool";
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
str2 << str;
|
str2 << str;
|
||||||
|
|
|
@ -2905,6 +2905,10 @@ private:
|
||||||
"bValue++;\n");
|
"bValue++;\n");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) The use of a variable of type bool with the ++ postfix operator is always true and deprecated by the C++ Standard.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (style) The use of a variable of type bool with the ++ postfix operator is always true and deprecated by the C++ Standard.\n", errout.str());
|
||||||
|
|
||||||
|
check("_Bool bValue = true;\n"
|
||||||
|
"bValue++;\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:2]: (style) The use of a variable of type bool with the ++ postfix operator is always true and deprecated by the C++ Standard.\n", errout.str());
|
||||||
|
|
||||||
check("void f(bool test){\n"
|
check("void f(bool test){\n"
|
||||||
" test++;\n"
|
" test++;\n"
|
||||||
"}");
|
"}");
|
||||||
|
|
|
@ -53,6 +53,7 @@ private:
|
||||||
TEST_CASE(tokenize17); // #2759
|
TEST_CASE(tokenize17); // #2759
|
||||||
TEST_CASE(tokenize18); // tokenize "(X&&Y)" into "( X && Y )" instead of "( X & & Y )"
|
TEST_CASE(tokenize18); // tokenize "(X&&Y)" into "( X && Y )" instead of "( X & & Y )"
|
||||||
TEST_CASE(tokenize19); // #3006 (segmentation fault)
|
TEST_CASE(tokenize19); // #3006 (segmentation fault)
|
||||||
|
TEST_CASE(tokenize20); // replace C99 _Bool => bool
|
||||||
|
|
||||||
// don't freak out when the syntax is wrong
|
// don't freak out when the syntax is wrong
|
||||||
TEST_CASE(wrong_syntax);
|
TEST_CASE(wrong_syntax);
|
||||||
|
@ -578,6 +579,11 @@ private:
|
||||||
tokenizeAndStringify("x < () <");
|
tokenizeAndStringify("x < () <");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tokenize20() // replace C99 _Bool => bool
|
||||||
|
{
|
||||||
|
ASSERT_EQUALS("bool a ; a = true ;", tokenizeAndStringify("_Bool a = true;"));
|
||||||
|
}
|
||||||
|
|
||||||
void wrong_syntax()
|
void wrong_syntax()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue