Another fix for handling of final/override specifiers in Tokenizer::simplifyKeyword() including a testcase. Ran astyle

This commit is contained in:
Alexander Mai 2015-05-23 20:51:15 +02:00
parent 355890375c
commit 7416d6add9
4 changed files with 46 additions and 23 deletions

View File

@ -9308,7 +9308,7 @@ void Tokenizer::simplifyKeyword()
}
}
if (_settings->standards.cpp >= Standards::CPP11) {
if (isCPP() && _settings->standards.cpp >= Standards::CPP11) {
for (Token *tok = list.front(); tok; tok = tok->next()) {
while (tok->str() == "constexpr") {
tok->deleteThis();
@ -9327,16 +9327,21 @@ void Tokenizer::simplifyKeyword()
//if (Token::Match(tok, ") override [{;]"))
if (Token::Match(tok, ") const|override|final")) {
Token* specifier = tok->tokAt(2);
while (specifier && Token::Match(specifier, "const|override|final"))
while (specifier && Token::Match(specifier, "const|override|final")) {
specifier=specifier->next();
}
if (specifier && Token::Match(specifier, "[{;]")) {
specifier=tok->next();
while (specifier->str()=="override" || specifier->str()=="final")
specifier = tok->next();
while (!Token::Match(specifier, "[{;]")) {
if (specifier->str()=="const")
specifier=specifier->next();
else
specifier->deleteThis();
}
}
}
}
}
}
void Tokenizer::simplifyAssignmentInFunctionCall()

View File

@ -4485,6 +4485,24 @@ private:
const char in4 [] = "struct B final : A { void foo(); };";
const char out4 [] = "struct B : A { void foo ( ) ; } ;";
ASSERT_EQUALS(out4, tokenizeAndStringify(in4));
const char in5 [] = "struct ArrayItemsValidator final {\n"
" SchemaError validate() const override {\n"
" for (; pos < value.size(); ++pos) {\n"
" }\n"
" return none;\n"
" }\n"
"};\n";
const char out5 [] =
"struct ArrayItemsValidator {\n"
"SchemaError validate ( ) const {\n"
"for ( ; pos < value . size ( ) ; ++ pos ) {\n"
"}\n"
"return none ;\n"
"}\n"
"} ;";
ASSERT_EQUALS(out5, tokenizeAndStringify(in5));
}
}