Support C++14 [[deprecated]]

This commit is contained in:
PKEuS 2015-05-10 12:35:47 +02:00
parent 8fa7b13a18
commit 77c5381612
3 changed files with 34 additions and 0 deletions

View File

@ -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",

View File

@ -681,6 +681,11 @@ public:
*/
void simplifyOperatorName();
/**
* Remove [[deprecated]] (C++14) from TokenList
*/
void simplifyDeprecated();
/**
* check for duplicate enum definition
*/

View File

@ -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;