diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 38c4ca573..2324fcccb 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3208,6 +3208,9 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) if (_settings->terminated()) return false; + // Remove [[deprecated]] + simplifyDeprecated(); + // Simplify the C alternative tokens (and, or, etc.) simplifyCAlternativeTokens(); @@ -10091,6 +10094,19 @@ void Tokenizer::removeUnnecessaryQualification() } } +void Tokenizer::simplifyDeprecated() +{ + if (_settings->standards.cpp != Standards::CPP11 || isC()) + return; // It is actually a C++14 feature, however, there seems to be nothing dangerous about removing it for C++11 as well + + for (Token *tok = list.front(); tok; tok = tok->next()) { + if (tok->link() && Token::simpleMatch(tok, "[ [ deprecated")) { + Token::eraseTokens(tok, tok->link()->next()); + tok->deleteThis(); + } + } +} + void Tokenizer::unnecessaryQualificationError(const Token *tok, const std::string &qualification) const { reportError(tok, Severity::portability, "unnecessaryQualification", diff --git a/lib/tokenize.h b/lib/tokenize.h index 3f294b870..68e7a29e7 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -681,6 +681,11 @@ public: */ void simplifyOperatorName(); + /** + * Remove [[deprecated]] (C++14) from TokenList + */ + void simplifyDeprecated(); + /** * check for duplicate enum definition */ diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 178255a06..e2377cbc6 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -455,6 +455,8 @@ private: TEST_CASE(simplifyMathExpressions); //ticket #1620 TEST_CASE(simplifyStaticConst); + TEST_CASE(simplifyDeprecated); + TEST_CASE(compileLimits); // #5592 crash: gcc: testsuit: gcc.c-torture/compile/limits-declparen.c // AST data @@ -8358,6 +8360,17 @@ private: ASSERT_EQUALS(expected2, tokenizeAndStringify(code2, true)); } + void simplifyDeprecated() { + ASSERT_EQUALS("int f ( ) ;", + tokenizeAndStringify("[[deprecated]] int f();", false, true, Settings::Unspecified, "test.cpp", true)); + + ASSERT_EQUALS("[ [ deprecated ] ] int f ( ) ;", + tokenizeAndStringify("[[deprecated]] int f();", false, true, Settings::Unspecified, "test.cpp", false)); + + ASSERT_EQUALS("[ [ deprecated ] ] int f ( ) ;", + tokenizeAndStringify("[[deprecated]] int f();", false, true, Settings::Unspecified, "test.c", true)); + } + static std::string testAst(const char code[],bool verbose=false) { // tokenize given code.. const Settings settings;