public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "adrianh.bsc at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug preprocessor/61638] "warning: multi-line comment" unclear and has false positives
Date: Mon, 06 Feb 2023 06:14:24 +0000	[thread overview]
Message-ID: <bug-61638-4-sW0e7tDyHx@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-61638-4@http.gcc.gnu.org/bugzilla/>

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

       reply	other threads:[~2023-02-06  6:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-61638-4@http.gcc.gnu.org/bugzilla/>
2023-02-06  6:14 ` adrianh.bsc at gmail dot com [this message]
2023-02-06  6:24 ` pinskia at gcc dot gnu.org
2023-02-07  3:14 ` adrianh.bsc at gmail dot com
2023-02-07  3:17 ` LpSolit at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-61638-4-sW0e7tDyHx@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).