Fixed #6931 (noexcept and override qualifiers plus less than operator results in a syntax error)

This commit is contained in:
Daniel Marjamäki 2016-01-03 12:22:07 +01:00
parent be2ab9eb12
commit cd89e68f60
3 changed files with 13 additions and 18 deletions

View File

@ -64,14 +64,12 @@ const Token * Tokenizer::isFunctionHead(const Token *tok, const std::string &end
tok = tok->next(); tok = tok->next();
return (endsWith.find(tok->str()) != std::string::npos) ? tok : nullptr; return (endsWith.find(tok->str()) != std::string::npos) ? tok : nullptr;
} }
if (isCPP() && (Token::Match(tok, ") const| throw|noexcept (") || Token::Match(tok, ") const| &|&&|noexcept| [;:{=]"))) { if (isCPP() && tok->str() == ")") {
tok = tok->next(); tok = tok->next();
while (tok->isName()) while (Token::Match(tok, "const|noexcept|override|volatile|&|&& !!("))
tok = tok->next(); tok = tok->next();
if (Token::Match(tok, "&|&&")) if (Token::Match(tok, "throw|noexcept ("))
tok = tok->next(); tok = tok->linkAt(1)->next();
if (tok->str() == "(")
tok = tok->link()->next();
if (Token::Match(tok, "= 0|default|delete ;")) if (Token::Match(tok, "= 0|default|delete ;"))
tok = tok->tokAt(2); tok = tok->tokAt(2);
return (tok && endsWith.find(tok->str()) != std::string::npos) ? tok : nullptr; return (tok && endsWith.find(tok->str()) != std::string::npos) ? tok : nullptr;
@ -2242,7 +2240,7 @@ Token * Tokenizer::startOfFunction(Token * tok) const
{ {
tok = tok->next(); tok = tok->next();
while (tok && tok->str() != "{") { while (tok && tok->str() != "{") {
if (isCPP() && Token::Match(tok, "const|volatile")) { if (isCPP() && Token::Match(tok, "const|volatile|override")) {
tok = tok->next(); tok = tok->next();
} else if (isCPP() && tok->str() == "noexcept") { } else if (isCPP() && tok->str() == "noexcept") {
tok = tok->next(); tok = tok->next();
@ -2272,7 +2270,7 @@ const Token * Tokenizer::startOfExecutableScope(const Token * tok)
bool inInit = false; bool inInit = false;
while (tok && tok->str() != "{") { while (tok && tok->str() != "{") {
if (!inInit) { if (!inInit) {
if (Token::Match(tok, "const|volatile")) { if (Token::Match(tok, "const|override|volatile")) {
tok = tok->next(); tok = tok->next();
} else if (tok->str() == "noexcept") { } else if (tok->str() == "noexcept") {
tok = tok->next(); tok = tok->next();
@ -9191,9 +9189,6 @@ void Tokenizer::simplifyKeyword()
} }
// final: // final:
// 2) void f() final; <- function is final // 2) void f() final; <- function is final
// override:
// void f() override;
//if (Token::Match(tok, ") override [{;]"))
if (Token::Match(tok, ") const|override|final")) { if (Token::Match(tok, ") const|override|final")) {
Token* specifier = tok->tokAt(2); Token* specifier = tok->tokAt(2);
while (specifier && Token::Match(specifier, "const|override|final")) { while (specifier && Token::Match(specifier, "const|override|final")) {
@ -9202,10 +9197,10 @@ void Tokenizer::simplifyKeyword()
if (specifier && Token::Match(specifier, "[{;]")) { if (specifier && Token::Match(specifier, "[{;]")) {
specifier = tok->next(); specifier = tok->next();
while (!Token::Match(specifier, "[{;]")) { while (!Token::Match(specifier, "[{;]")) {
if (specifier->str()=="const") if (specifier->str()=="final")
specifier=specifier->next();
else
specifier->deleteThis(); specifier->deleteThis();
else
specifier=specifier->next();
} }
} }
} }

View File

@ -3844,7 +3844,6 @@ private:
ASSERT_EQUALS("int foo ( ) { }", tok("__inline int foo ( ) { }", true)); ASSERT_EQUALS("int foo ( ) { }", tok("__inline int foo ( ) { }", true));
ASSERT_EQUALS("int foo ( ) { }", tok("__forceinline int foo ( ) { }", true)); ASSERT_EQUALS("int foo ( ) { }", tok("__forceinline int foo ( ) { }", true));
ASSERT_EQUALS("int foo ( ) { }", tok("constexpr int foo() { }", true)); ASSERT_EQUALS("int foo ( ) { }", tok("constexpr int foo() { }", true));
ASSERT_EQUALS("class C { int f ( ) ; } ;", tok("class C { int f() override ; };", true));
ASSERT_EQUALS("class C { int f ( ) ; } ;", tok("class C { int f() final ; };", true)); ASSERT_EQUALS("class C { int f ( ) ; } ;", tok("class C { int f() final ; };", true));
ASSERT_EQUALS("void f ( ) { int final [ 10 ] ; }", tok("void f() { int final[10]; }", true)); ASSERT_EQUALS("void f ( ) { int final [ 10 ] ; }", tok("void f() { int final[10]; }", true));
ASSERT_EQUALS("int * p ;", tok("int * __restrict p;", "test.c")); ASSERT_EQUALS("int * p ;", tok("int * __restrict p;", "test.c"));

View File

@ -4011,13 +4011,13 @@ private:
" virtual int test() final override;" " virtual int test() final override;"
"};"; "};";
const char out2[] = "class Derived {\n" const char out2[] = "class Derived {\n"
"virtual int test ( ) ; } ;"; "virtual int test ( ) override ; } ;";
ASSERT_EQUALS(out2, tokenizeAndStringify(in2)); ASSERT_EQUALS(out2, tokenizeAndStringify(in2));
const char in3[] = "class Derived{\n" const char in3[] = "class Derived{\n"
" virtual int test() final override const;" " virtual int test() final override const;"
"};"; "};";
const char out3[] = "class Derived {\n" const char out3[] = "class Derived {\n"
"virtual int test ( ) const ; } ;"; "virtual int test ( ) override const ; } ;";
ASSERT_EQUALS(out3, tokenizeAndStringify(in3)); ASSERT_EQUALS(out3, tokenizeAndStringify(in3));
const char in4 [] = "struct B final : A { void foo(); };"; const char in4 [] = "struct B final : A { void foo(); };";
@ -4033,7 +4033,7 @@ private:
"};\n"; "};\n";
const char out5 [] = const char out5 [] =
"struct ArrayItemsValidator {\n" "struct ArrayItemsValidator {\n"
"SchemaError validate ( ) const {\n" "SchemaError validate ( ) const override {\n"
"for ( ; pos < value . size ( ) ; ++ pos ) {\n" "for ( ; pos < value . size ( ) ; ++ pos ) {\n"
"}\n" "}\n"
"return none ;\n" "return none ;\n"
@ -8320,6 +8320,7 @@ private:
ASSERT(isStartOfExecutableScope(3, "void foo() { }")); ASSERT(isStartOfExecutableScope(3, "void foo() { }"));
ASSERT(isStartOfExecutableScope(3, "void foo() const { }")); ASSERT(isStartOfExecutableScope(3, "void foo() const { }"));
ASSERT(isStartOfExecutableScope(3, "void foo() volatile { }")); ASSERT(isStartOfExecutableScope(3, "void foo() volatile { }"));
ASSERT(isStartOfExecutableScope(3, "void foo() override { }"));
ASSERT(isStartOfExecutableScope(3, "void foo() noexcept { }")); ASSERT(isStartOfExecutableScope(3, "void foo() noexcept { }"));
ASSERT(isStartOfExecutableScope(3, "void foo() NOEXCEPT { }")); ASSERT(isStartOfExecutableScope(3, "void foo() NOEXCEPT { }"));
ASSERT(isStartOfExecutableScope(3, "void foo() CONST NOEXCEPT { }")); ASSERT(isStartOfExecutableScope(3, "void foo() CONST NOEXCEPT { }"));