Improve handling of 'final' in class declaration (#4706)
This commit is contained in:
parent
689dfd29c1
commit
9cf934c10d
|
@ -8485,6 +8485,10 @@ void Tokenizer::simplifyKeyword()
|
||||||
// 1) struct name final { }; <- struct is final
|
// 1) struct name final { }; <- struct is final
|
||||||
if (Token::Match(tok->previous(), "struct|class|union %type%")) {
|
if (Token::Match(tok->previous(), "struct|class|union %type%")) {
|
||||||
Token* finalTok = tok->next();
|
Token* finalTok = tok->next();
|
||||||
|
if (tok->isUpperCaseName() && Token::Match(finalTok, "%type%") && finalTok->str() != "final") {
|
||||||
|
tok = finalTok;
|
||||||
|
finalTok = finalTok->next();
|
||||||
|
}
|
||||||
if (Token::simpleMatch(finalTok, "<")) { // specialization
|
if (Token::simpleMatch(finalTok, "<")) { // specialization
|
||||||
finalTok = finalTok->findClosingBracket();
|
finalTok = finalTok->findClosingBracket();
|
||||||
if (finalTok)
|
if (finalTok)
|
||||||
|
|
|
@ -2573,6 +2573,8 @@ private:
|
||||||
ASSERT_EQUALS("static void * thread_local_var ; "
|
ASSERT_EQUALS("static void * thread_local_var ; "
|
||||||
"void * thread_local_var_2 ;", tokenizeAndStringify(code));
|
"void * thread_local_var_2 ;", tokenizeAndStringify(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASSERT_EQUALS("class Fred { } ;", tokenizeAndStringify("class DLLEXPORT Fred final { };"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void implicitIntConst() {
|
void implicitIntConst() {
|
||||||
|
@ -6647,7 +6649,7 @@ private:
|
||||||
void removeMacroInClassDef() { // #6058
|
void removeMacroInClassDef() { // #6058
|
||||||
ASSERT_EQUALS("class Fred { } ;", tokenizeAndStringify("class DLLEXPORT Fred { } ;"));
|
ASSERT_EQUALS("class Fred { } ;", tokenizeAndStringify("class DLLEXPORT Fred { } ;"));
|
||||||
ASSERT_EQUALS("class Fred : Base { } ;", tokenizeAndStringify("class Fred FINAL : Base { } ;"));
|
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:
|
// Regression for C code:
|
||||||
ASSERT_EQUALS("struct Fred { } ;", tokenizeAndStringify("struct DLLEXPORT Fred { } ;", true, Settings::Native, "test.c"));
|
ASSERT_EQUALS("struct Fred { } ;", tokenizeAndStringify("struct DLLEXPORT Fred { } ;", true, Settings::Native, "test.c"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue