Remove continuation line in code snippet to prevent GCC warning about
multiline comments (-Wcomment) when building a project using libclang
with GCC.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
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 //.
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.
#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.
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.