This is an archive of the discontinued LLVM Phabricator instance.

[AST][NFC] Silence GCC warning about multiline comments
ClosedPublic

Authored by thopre on Dec 1 2020, 10:26 AM.

Details

Summary

Remove continuation line in code snippet to prevent GCC warning about
multiline comments (-Wcomment) when building a project using libclang
with GCC.

Diff Detail

Event Timeline

thopre created this revision.Dec 1 2020, 10:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 1 2020, 10:26 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
thopre requested review of this revision.Dec 1 2020, 10:26 AM

I would just remove this extra symbol.

I would just remove this extra symbol.

But then the example code is no longer copy/pastable. Note that I expect people to copy/paste but it's nice if it looks authentic. Note that I don't mind either way.

Let's just disable this broken GCC warning. IIRC, the corresponding clang warning covers the actual bugs caused by line continuation in comments, and doesn't warn if the next line begins with a //.

Let's just disable this broken GCC warning. IIRC, the corresponding clang warning covers the actual bugs caused by line continuation in comments, and doesn't warn if the next line begins with a //.

Is there a way to disable it from the header? I've noticed this warning when compiling an application using libclang with g++. So I'm looking for a fix outside clang's build system which is not used in that case.

Let's just disable this broken GCC warning. IIRC, the corresponding clang warning covers the actual bugs caused by line continuation in comments, and doesn't warn if the next line begins with a //.

Is there a way to disable it from the header? I've noticed this warning when compiling an application using libclang with g++. So I'm looking for a fix outside clang's build system which is not used in that case.

Ping?

Is there a way to disable it from the header? I've noticed this warning when compiling an application using libclang with g++. So I'm looking for a fix outside clang's build system which is not used in that case.

Ping?

#pragma GCC diagnostic ignored (https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html) can do it. Now, we can't reasonably guarantee that Clang headers won't cause arbitrary broken warnings to fire, so there's a judgment call here on the extent to which we should carry changes to support use of such warning flags (versus expecting the code including the header to disable the warning). In this case, it's probably worth it, though, because the warning in question is part of GCC's -Wall.

Is there a way to disable it from the header? I've noticed this warning when compiling an application using libclang with g++. So I'm looking for a fix outside clang's build system which is not used in that case.

Ping?

#pragma GCC diagnostic ignored (https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html) can do it. Now, we can't reasonably guarantee that Clang headers won't cause arbitrary broken warnings to fire, so there's a judgment call here on the extent to which we should carry changes to support use of such warning flags (versus expecting the code including the header to disable the warning). In this case, it's probably worth it, though, because the warning in question is part of GCC's -Wall.

The documentation for that pragma says:

Note that not all diagnostics are modifiable; at the moment only warnings (normally controlled by ‘-W…’) can be controlled, and not all of them.

Unfortunately -Wcomment seems to be one of them as the pragma has no effect on the warning, at least with GCC 7, I haven't tried other versions.

thopre added a comment.Jan 5 2021, 6:29 AM

Is there a way to disable it from the header? I've noticed this warning when compiling an application using libclang with g++. So I'm looking for a fix outside clang's build system which is not used in that case.

Ping?

#pragma GCC diagnostic ignored (https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html) can do it. Now, we can't reasonably guarantee that Clang headers won't cause arbitrary broken warnings to fire, so there's a judgment call here on the extent to which we should carry changes to support use of such warning flags (versus expecting the code including the header to disable the warning). In this case, it's probably worth it, though, because the warning in question is part of GCC's -Wall.

The documentation for that pragma says:

Note that not all diagnostics are modifiable; at the moment only warnings (normally controlled by ‘-W…’) can be controlled, and not all of them.

Unfortunately -Wcomment seems to be one of them as the pragma has no effect on the warning, at least with GCC 7, I haven't tried other versions.

Ping?

People can't actually just copy/paste from the comment anyway because of the comment characters on the line, and I don't think anyone will misunderstand the example if the backslash is missing. It's silly that GCC has a problem with this, but since it does, let's just work around the problem and drop the backslash rather than having one comment block in the header use a different style.

thopre updated this revision to Diff 315080.Jan 7 2021, 2:53 AM

Change approach to remove continuation line instead

thopre edited the summary of this revision. (Show Details)Jan 7 2021, 2:53 AM
thopre added a comment.Jan 7 2021, 2:56 AM

People can't actually just copy/paste from the comment anyway because of the comment characters on the line, and I don't think anyone will misunderstand the example if the backslash is missing. It's silly that GCC has a problem with this, but since it does, let's just work around the problem and drop the backslash rather than having one comment block in the header use a different style.

They can from the online documentation (https://clang.llvm.org/doxygen/classclang_1_1OMPDeclareReductionDecl.html#details) but since other approaches are unfortunately not working this is probably the best approach indeed.

rjmccall accepted this revision.Jan 7 2021, 8:56 AM

Okay, LGTM.

This revision is now accepted and ready to land.Jan 7 2021, 8:56 AM
This revision was automatically updated to reflect the committed changes.