https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61638
Jack Adrian Zappa <adrianh.bsc at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |adrianh.bsc at gmail dot com --- Comment #9 from Jack Adrian Zappa <adrianh.bsc at gmail dot com> --- Issue: Cannot turn off the `-Wcomment` option using `#pragma GCC diagnostic ignored "-Wcomment"`. This is causing issues when I'm trying to document my macros and how to write them. Our coding standards at my work state that we are to use /// for documenting functions/variables/macros and not /** */. I grudgingly tried to use a space after the \, but that didn't work either. Also inadvertently found that ending with a double backslash (\\) also didn't work for some reason, which is odd because the backslash is escaped, so it cannot cause a comment continuation. Suggest fix is to either: 1. Change the phase where this warning/error/ignored is tested so that the #pragma GCC diagnostic is honoured or 2. If a line comment end in an \ but the next line is a comment, then do the same thing as is done for a multi-line comment, ignore it as not an issue. In addition, a line comment ending in an escaped backslash shouldn't cause any issue. It would be also preferable that an escaped whitespace that is not an eol character would be accepted (though it seems that this is unlikely given bug 8270). GCC versions tested on: 7.5, 11.3 12.2 System type: MSYS2 and whatever is running under godbolt.org Options given: -Wall -Werror Complete command line: g++ -Wall -Werror bug.cpp Source file: $ cat bug.cpp #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcomment" /// #define macro_to_document(x) \ /// blah blah x blah /// /// Also doesn't work with a space after the \ /// as in this case. /// /// Also doesn't work with a double backslash \\ /// as in this case. /// #pragma GCC diagnostic pop Compiler output: $ g++ -v -Wall -Werror -save-temps bug.cpp Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-msys/11.3.0/lto-wrapper.exe Target: x86_64-pc-msys Configured with: /c/S/gcc/src/gcc-11.3.0/configure --build=x86_64-pc-msys --prefix=/usr --libexecdir=/usr/lib --enable-bootstrap --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --with-arch=x86-64 --with-tune=generic --disable-multilib --enable-__cxa_atexit --with-dwarf2 --enable-languages=c,c++,fortran,lto --enable-graphite --enable-threads=posix --enable-libatomic --enable-libgomp --disable-libitm --enable-libquadmath --enable-libquadmath-support --disable-libssp --disable-win32-registry --disable-symvers --with-gnu-ld --with-gnu-as --disable-isl-version-check --enable-checking=release --without-libiconv-prefix --without-libintl-prefix --with-system-zlib --enable-linker-build-id --with-default-libstdcxx-abi=gcc4-compatible --enable-libstdcxx-filesystem-ts Thread model: posix Supported LTO compression algorithms: zlib gcc version 11.3.0 (GCC) COLLECT_GCC_OPTIONS='-v' '-Wall' '-Werror' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a-' /usr/lib/gcc/x86_64-pc-msys/11.3.0/cc1plus.exe -E -quiet -v -idirafter /usr/lib/gcc/x86_64-pc-msys/11.3.0/../../../../lib/../include/w32api -idirafter /usr/lib/gcc/x86_64-pc-msys/11.3.0/../../../../x86_64-pc-msys/lib/../lib/../../include/w32api bug.cpp -mtune=generic -march=x86-64 -Wall -Werror -fpch-preprocess -o a-bug.ii ignoring nonexistent directory "/usr/local/include" ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-msys/11.3.0/../../../../x86_64-pc-msys/include" ignoring duplicate directory "/usr/lib/gcc/x86_64-pc-msys/11.3.0/../../../../x86_64-pc-msys/lib/../lib/../../include/w32api" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/x86_64-pc-msys/11.3.0/include/c++ /usr/lib/gcc/x86_64-pc-msys/11.3.0/include/c++/x86_64-pc-msys /usr/lib/gcc/x86_64-pc-msys/11.3.0/include/c++/backward /usr/lib/gcc/x86_64-pc-msys/11.3.0/include /usr/lib/gcc/x86_64-pc-msys/11.3.0/include-fixed /usr/include /usr/lib/gcc/x86_64-pc-msys/11.3.0/../../../../lib/../include/w32api End of search list. bug.cpp:3:1: error: multi-line comment [-Werror=comment] 3 | /// #define macro_to_document(x) \ | ^ bug.cpp:6:1: error: multi-line comment [-Werror=comment] 6 | /// Also doesn't work with a space after the \ | ^ bug.cpp:9:1: error: multi-line comment [-Werror=comment] 9 | /// Also doesn't work with a double backslash \\ | ^ cc1plus: all warnings being treated as errors Preprocessed file: $ cat a-bug.ii # 0 "bug.cpp" # 0 "<built-in>" # 0 "<command-line>" # 1 "bug.cpp" #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcomment" # 12 "bug.cpp" #pragma GCC diagnostic pop