Skip to content

Commit 9cf934c

Browse files
Improve handling of 'final' in class declaration (danmar#4706)
1 parent 689dfd2 commit 9cf934c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/tokenize.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8485,6 +8485,10 @@ void Tokenizer::simplifyKeyword()
84858485
// 1) struct name final { }; <- struct is final
84868486
if (Token::Match(tok->previous(), "struct|class|union %type%")) {
84878487
Token* finalTok = tok->next();
8488+
if (tok->isUpperCaseName() && Token::Match(finalTok, "%type%") && finalTok->str() != "final") {
8489+
tok = finalTok;
8490+
finalTok = finalTok->next();
8491+
}
84888492
if (Token::simpleMatch(finalTok, "<")) { // specialization
84898493
finalTok = finalTok->findClosingBracket();
84908494
if (finalTok)

test/testtokenize.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2573,6 +2573,8 @@ class TestTokenizer : public TestFixture {
25732573
ASSERT_EQUALS("static void * thread_local_var ; "
25742574
"void * thread_local_var_2 ;", tokenizeAndStringify(code));
25752575
}
2576+
2577+
ASSERT_EQUALS("class Fred { } ;", tokenizeAndStringify("class DLLEXPORT Fred final { };"));
25762578
}
25772579

25782580
void implicitIntConst() {
@@ -6647,7 +6649,7 @@ class TestTokenizer : public TestFixture {
66476649
void removeMacroInClassDef() { // #6058
66486650
ASSERT_EQUALS("class Fred { } ;", tokenizeAndStringify("class DLLEXPORT Fred { } ;"));
66496651
ASSERT_EQUALS("class Fred : Base { } ;", tokenizeAndStringify("class Fred FINAL : Base { } ;"));
6650-
ASSERT_EQUALS("class Fred final : Base { } ;", tokenizeAndStringify("class DLLEXPORT Fred final : Base { } ;")); // #11422
6652+
ASSERT_EQUALS("class Fred : Base { } ;", tokenizeAndStringify("class DLLEXPORT Fred final : Base { } ;")); // #11422
66516653
// Regression for C code:
66526654
ASSERT_EQUALS("struct Fred { } ;", tokenizeAndStringify("struct DLLEXPORT Fred { } ;", true, Settings::Native, "test.c"));
66536655
}

0 commit comments

Comments
 (0)