https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120249
Bug ID: 120249 Summary: Improve handling of comments with -C similarly to clang Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: preprocessor Assignee: unassigned at gcc dot gnu.org Reporter: federico at kircheis dot it Target Milestone: --- Consider following program ---- #define CPP_PP_CAT_(X, ...) X ## __VA_ARGS__ #define CPP_PP_CAT(X, ...) CPP_PP_CAT_(X, __VA_ARGS__) int bar(){ // comment 1 int /*comment2*/ CPP_PP_CAT(a, // comment 3 b) = 12; // comment4 return ab; } ---- GCC, when using "-E -C" triggers the error > pasting "a" and "/* comment 3*/" does not give a valid preprocessing token Which is correct. On the other hand, clang also supports "-E -C" and discards "// comment 3" to let the proprocessor do its work, but keeps all other comments. Since the (documented) intended usage for "-C" is to keep comments relevant for linters, it should be better if a comments is discarded instead of retained and leading to an error. Especially since the comment might be irrelevant for the linter. Example on godbolt: https://godbolt.org/z/1h858bnaW