Skip to content

Fix #680: Add option to keep comments in preprocessed code#681

Open
ludviggunne wants to merge 3 commits into
cppcheck-opensource:masterfrom
ludviggunne:keep-comments
Open

Fix #680: Add option to keep comments in preprocessed code#681
ludviggunne wants to merge 3 commits into
cppcheck-opensource:masterfrom
ludviggunne:keep-comments

Conversation

@ludviggunne

Copy link
Copy Markdown
Contributor

No description provided.

@danmar danmar left a comment

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.

I don't see the use case to treat comments differently in the source file and in included files. do you know the reason?

@danmar

danmar commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

The removeComments was added in #340 and it seems that it was added for performance reasons only, there is no known use case as far as I see when we want to only remove the comments in the included files.

So I suggest that we just keep the removeComments flag. If that is false then keep all comments. If that is true the remove all comments.

The performance optimisation might be less interesting after Tommys recent fix also so that files are not redundantly loaded.

Comment thread test.cpp

{
const char code[] = "#define MACRO /* comment */\nMACRO\n";
ASSERT_EQUALS("\n/* comment */", preprocess(code,dui));

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.

this may be questionable. do we want that comments are expanded. maybe the comment should only be kept on line 1.

but for now .. as far as I see it does not matter much. If somebody has strong opinions later and wants to change I am not against changing..

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