From 5c7ed46e0cb6ffeee17a9185d1ccaa9d9781b560 Mon Sep 17 00:00:00 2001 From: seb777 Date: Sat, 3 Sep 2011 23:10:16 +0200 Subject: [PATCH] Following the discussion XX, replace the keyword C99 '_Bool' with the 'bool' keyword in the process of tokenization\nSee https://github.com/danmar/cppcheck/commit/f29b7f9f087779d789e8bdc24745930623f314ca --- lib/checkother.cpp | 2 +- lib/tokenize.cpp | 4 ++++ test/testother.cpp | 4 ++++ test/testtokenize.cpp | 6 ++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 480cf1d20..3b52f916a 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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) == "&" ? "&&" : "||"); } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 10acc1fb8..4caffa888 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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; diff --git a/test/testother.cpp b/test/testother.cpp index a0c7812eb..d3fec92a7 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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" "}"); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index f14310ce4..b43aa7226 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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() { {