Skip to content

Commit 44559a1

Browse files
IOBYTEdanmar
authored andcommitted
Fixed cppcheck-opensource#5069 (sizeof(void) when variable name is override)
1 parent 5641833 commit 44559a1

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

lib/tokenize.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9246,7 +9246,7 @@ void Tokenizer::simplifyKeyword()
92469246

92479247
if (_settings->standards.cpp >= Standards::CPP11) {
92489248
for (Token *tok = list.front(); tok; tok = tok->next()) {
9249-
while (Token::Match(tok, "constexpr|override")) {
9249+
while (tok->str() == "constexpr") {
92509250
tok->deleteThis();
92519251
}
92529252

@@ -9255,6 +9255,13 @@ void Tokenizer::simplifyKeyword()
92559255
// struct name final { }; <- struct is final
92569256
if (Token::Match(tok, ") final [{;]") || Token::Match(tok, "%type% final [:{]"))
92579257
tok->deleteNext();
9258+
9259+
// override
9260+
// void f() override;
9261+
else if (Token::Match(tok, ") override [{;]"))
9262+
tok->deleteNext();
9263+
else if (Token::Match(tok, ") const override [{;]"))
9264+
tok->next()->deleteNext();
92589265
}
92599266
}
92609267
}

test/testsimplifytokens.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ class TestSimplifyTokens : public TestFixture {
447447

448448
TEST_CASE(simplifyArrayAddress); // Replace "&str[num]" => "(str + num)"
449449
TEST_CASE(simplifyCharAt);
450+
TEST_CASE(simplifyOverride); // ticket #5069
450451
}
451452

452453
std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Unspecified) {
@@ -8237,6 +8238,16 @@ class TestSimplifyTokens : public TestFixture {
82378238
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 ( ) ) ; }",
82388239
tok(code, true));
82398240
}
8241+
8242+
void simplifyOverride() { // ticket #5069
8243+
const char code[] = "void fun() {\n"
8244+
" unsigned char override[] = {0x01, 0x02};\n"
8245+
" doSomething(override, sizeof(override));\n"
8246+
"}\n";
8247+
ASSERT_EQUALS("void fun ( ) { char override [ 2 ] = { 1 , 2 } ; doSomething ( override , 2 ) ; }",
8248+
tok(code, true));
8249+
}
8250+
82408251
};
82418252

82428253
REGISTER_TEST(TestSimplifyTokens)

0 commit comments

Comments
 (0)