diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2803346fd..304ed67cb 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9246,7 +9246,7 @@ void Tokenizer::simplifyKeyword() if (_settings->standards.cpp >= Standards::CPP11) { for (Token *tok = list.front(); tok; tok = tok->next()) { - while (Token::Match(tok, "constexpr|override")) { + while (tok->str() == "constexpr") { tok->deleteThis(); } @@ -9255,6 +9255,13 @@ void Tokenizer::simplifyKeyword() // struct name final { }; <- struct is final if (Token::Match(tok, ") final [{;]") || Token::Match(tok, "%type% final [:{]")) tok->deleteNext(); + + // override + // void f() override; + else if (Token::Match(tok, ") override [{;]")) + tok->deleteNext(); + else if (Token::Match(tok, ") const override [{;]")) + tok->next()->deleteNext(); } } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 68bab111a..bf9d2dbf5 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -447,6 +447,7 @@ private: TEST_CASE(simplifyArrayAddress); // Replace "&str[num]" => "(str + num)" TEST_CASE(simplifyCharAt); + TEST_CASE(simplifyOverride); // ticket #5069 } std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Unspecified) { @@ -8237,6 +8238,16 @@ private: ASSERT_EQUALS("int evallex ( ) { int c ; int t ; do { c = macroid ( c ) ; if ( c == EOF_CHAR || c == '\n' ) { } t = type [ c ] ; } while ( t == LET && catenate ( ) ) ; }", tok(code, true)); } + + void simplifyOverride() { // ticket #5069 + const char code[] = "void fun() {\n" + " unsigned char override[] = {0x01, 0x02};\n" + " doSomething(override, sizeof(override));\n" + "}\n"; + ASSERT_EQUALS("void fun ( ) { char override [ 2 ] = { 1 , 2 } ; doSomething ( override , 2 ) ; }", + tok(code, true)); + } + }; REGISTER_TEST(TestSimplifyTokens)