Improve handling of 'final' in class declaration (#4706)

This commit is contained in:
chrchr-github 2023-01-18 17:08:43 +01:00 committed by GitHub
parent 689dfd29c1
commit 9cf934c10d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -8485,6 +8485,10 @@ void Tokenizer::simplifyKeyword()
// 1) struct name final { }; <- struct is final
if (Token::Match(tok->previous(), "struct|class|union %type%")) {
Token* finalTok = tok->next();
if (tok->isUpperCaseName() && Token::Match(finalTok, "%type%") && finalTok->str() != "final") {
tok = finalTok;
finalTok = finalTok->next();
}
if (Token::simpleMatch(finalTok, "<")) { // specialization
finalTok = finalTok->findClosingBracket();
if (finalTok)

View File

@ -2573,6 +2573,8 @@ private:
ASSERT_EQUALS("static void * thread_local_var ; "
"void * thread_local_var_2 ;", tokenizeAndStringify(code));
}
ASSERT_EQUALS("class Fred { } ;", tokenizeAndStringify("class DLLEXPORT Fred final { };"));
}
void implicitIntConst() {
@ -6647,7 +6649,7 @@ private:
void removeMacroInClassDef() { // #6058
ASSERT_EQUALS("class Fred { } ;", tokenizeAndStringify("class DLLEXPORT Fred { } ;"));
ASSERT_EQUALS("class Fred : Base { } ;", tokenizeAndStringify("class Fred FINAL : Base { } ;"));
ASSERT_EQUALS("class Fred final : Base { } ;", tokenizeAndStringify("class DLLEXPORT Fred final : Base { } ;")); // #11422
ASSERT_EQUALS("class Fred : Base { } ;", tokenizeAndStringify("class DLLEXPORT Fred final : Base { } ;")); // #11422
// Regression for C code:
ASSERT_EQUALS("struct Fred { } ;", tokenizeAndStringify("struct DLLEXPORT Fred { } ;", true, Settings::Native, "test.c"));
}