Skip to content

Improve handling of 'final' in class declaration#4706

Merged
danmar merged 3 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_MacroFinal
Jan 18, 2023
Merged

Improve handling of 'final' in class declaration#4706
danmar merged 3 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_MacroFinal

Conversation

@chrchr-github
Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread lib/tokenize.cpp
// 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") {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm.. this is a guessing game.. theoretically I think your guess could go wrong in such code:

class C FINAL {};

Could we try to bailout if we are unsure?

You could make this check more explicit. You could check that finalTok is not uppercase. Or how about Token::Match(finalTok, "%type% final")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class C FINAL {}; gives test.cpp:1:1: information: The code 'class C FINAL {' is not handled. You can use -I or --include to add handling of this code. [class_X_Y] even without this change.
We cannot bail out in the tokenizer, since it might be a valid variable declaration, see https://github.com/danmar/cppcheck/actions/runs/3920131345/jobs/6701567873

@danmar danmar merged commit 9cf934c into cppcheck-opensource:main Jan 18, 2023
@chrchr-github chrchr-github deleted the chr_MacroFinal branch February 1, 2023 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants