Skip to content

Keep comments #433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Keep comments #433

wants to merge 1 commit into from

Conversation

osesov
Copy link

@osesov osesov commented Jun 3, 2025

Keep comments in the main text, not only in defines

@danmar
Copy link
Owner

danmar commented Jun 12, 2025

@osesov @firewave I don't feel I understand the removeComments. please share your thoughts.

It says:

    bool removeComments; /** remove comment tokens from included files */

why would somebody want to remove comment tokens in included files but keep them in source file?

why is comment tokens added at all to the token list if removeComments is true.

it is not clear to me that we want to have comments in the preprocessor output at all. It's not clear to me if all macro expansions will work fine if there are comments kept.. i.e.:

#define XY(X,Y)    X /*a*/ ## /*b*/ Y

@danmar
Copy link
Owner

danmar commented Jun 12, 2025

Cppcheck needs to be able to fetch comments. But off the top of my head it fetches the comments from the "raw tokenlists". cppcheck does not expect comment tokens in the "preprocess" output if I am not mistaken.

@osesov
Copy link
Author

osesov commented Jun 20, 2025

Natural behaviour of C preprocessor is to remove all comments. GCC's cpp allows -C flag to keep comments in the source code (also there is -CC flag, but this is out of scope).

Current behaviour of simplecpp is that:

If DUI::removeComments flag is true all the comments are removed. Just as expected. The comment you quoting seems to be misleading: comments are removed both from the main file and all the included files.

When DUI::removeComments is false, when some comments are removed, while some are kept: code keeps comments, coming from macro bodies, but ignores the comments coming from text (regardless whether it is main file or included file).

Taking this as example:

#define A 1 /* macro comment */
A /* text comment */

with 'DUI::removeComments = false` it will be expanded to (note that text comment has disappeared):


1 /* macro comment */

This commit would result in following:


1 /* macro comment */ /* text comment */

@osesov
Copy link
Author

osesov commented Jun 20, 2025

#define XY(X,Y)    X /*a*/ ## /*b*/ Y

you right these expansion do not work. No reason to apply this change then.

@osesov osesov closed this Jun 20, 2025
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