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:
seb777 2011-09-03 23:10:16 +02:00
parent 46b5d5bd00
commit 5c7ed46e0c
4 changed files with 15 additions and 1 deletions

View File

@ -237,7 +237,7 @@ void CheckOther::checkBitwiseOnBoolean()
{
const Variable *var = _tokenizer->getSymbolDatabase()->getVariableFromVarId(tok->next()->varId());
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) == "&" ? "&&" : "||");
}

View File

@ -145,6 +145,10 @@ void Tokenizer::addtoken(const char str[], const unsigned int lineno, const unsi
{
str2 << std::strtoul(str + 2, NULL, 16);
}
else if (strncmp(str, "_Bool", 5) == 0)
{
str2 << "bool";
}
else
{
str2 << str;

View File

@ -2905,6 +2905,10 @@ private:
"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("_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"
" test++;\n"
"}");

View File

@ -53,6 +53,7 @@ private:
TEST_CASE(tokenize17); // #2759
TEST_CASE(tokenize18); // tokenize "(X&&Y)" into "( X && Y )" instead of "( X & & Y )"
TEST_CASE(tokenize19); // #3006 (segmentation fault)
TEST_CASE(tokenize20); // replace C99 _Bool => bool
// don't freak out when the syntax is wrong
TEST_CASE(wrong_syntax);
@ -578,6 +579,11 @@ private:
tokenizeAndStringify("x < () <");
}
void tokenize20() // replace C99 _Bool => bool
{
ASSERT_EQUALS("bool a ; a = true ;", tokenizeAndStringify("_Bool a = true;"));
}
void wrong_syntax()
{
{