diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 77ed03f18..bb1407aa3 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index ec6f32464..e175ac204 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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")); }